Skip to content

Points command should be reentrant so that concurrent processes in the grader do not mishandle the final points #10

@markkuriekkinen

Description

@markkuriekkinen

If the exercise grader running in the container uses concurrent processing somehow, then using the points command is not safe because points is not reentrant yet. It is thus possible, that process/thread A reads the points file, but process/thread B then reads and writes the points file before process A reaches the part for writing the points file. Then, the final points would not include any results that were handled by process B because they are overwritten by process A. Process A did not "see" any points from B when A was initially reading the points file.

It would be best to make points reentrant by explicitly locking the file (e.g., with flock https://stackoverflow.com/a/17480020).

The points command:
https://github.com/apluslms/grading-base/blob/master/bin/points

The flock command is already available in the grading-base container so I don't think we need to install any new packages.

The points file is read on this line:

IFS=/ read points max_points < $pfile

And the points file is written on this file:
echo "$points/$max_points" > $pfile

Do we need to lock both reading and writing the points file? I think so since we don't want any "process A" to read the points file just before another process is writing its changes to the points file. I think this also means that the lock must be held from the time of reading the points file to the time of writing the points file. If the lock is released between the reading and writing operations, then another process could modify the points file after someone has read the file, but before the file has been written.

Internal ticket from the teacher:
https://rt.cs.aalto.fi/Ticket/Display.html?id=24484


https://en.wikipedia.org/wiki/Reentrancy_(computing)


Differences between flock and lockf:
https://stackoverflow.com/questions/22409780/flock-vs-lockf-on-linux
flock only works on local filesystems while lockf works on NFS too.
In the grading container, if the lock file is written under the /var/ directory, I think that is under the local disk.
Filepaths /submission and /exercise are on NFS.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions