Skip to content

Replace file locks with invocations to a centralised queue server over HTTP - #37

Closed
debater-coder wants to merge 3 commits into
seL4:masterfrom
au-ts:hamzah/lock-server
Closed

debater-coder wants to merge 3 commits into
seL4:masterfrom
au-ts:hamzah/lock-server

Conversation

@debater-coder

@debater-coder debater-coder commented Nov 24, 2026 •

Copy link
Copy Markdown

This PR replaces the use of file locks on tftp.keg.cse.unsw.edu.au with invocations to the lock server API at https://trustworthy.systems/mq/. The source for the server and additional documentation is provided here.

The linked repository contains a HTTP server and a client CLI for interfacing with that server. From my README:

This repository is split into a HTTP server and a CLI client to be called by both mq.sh and iq.sh. All server state (machines, lock status) is stored in a SQLite database, the server program itself is a stateless interface to that database. Access to machines is governed in a FIFO fashion, where a client posts a 'job' for a machine, then can poll that job until it is ready, and then release the job. This also means a single user can push multiple jobs to run in succession, which was not possible in the old locking interface. Polling a job is done with HTTP long polling (the server keeps open the connection for some time) to reduce overhead and allow clients to acquire locks sooner.

Visit documentation for the server or the client in their respective READMEs.

Why make this change?

In the current system, machine queue locks are acquired by running lockfile command over SSH, and released by deleting the lock file. This has a number of disadvantages:

Waiting time

Currently multiple SSH connections are established and closed in succession in the process of acquiring a lock. If the user is outside the keg network, these connections will also go through SSH bastions adding additional latency. This adds to several seconds of latency when outside the keg network.
In contrast, the system implemented in my PR uses HTTP proxied over nginx, which leads to noticably faster lock acquisition. The client also reuses TCP connections (the library used by the CLI client uses HTTP persistent connections by default), so when multiple requests are needed (for example to display information about jobs in the queue before acquiring the lock) there will be no repeated opening/closing of connections.
This system also uses HTTP long polling, meaning that the server holds the connection open for a given (server-configurable) period, and if it is the clients turn to acquire the lock the server will send a HTTP response early to notify the client immediately. Thus, the system is effectively event-based rather than poling-based.

Fairness

In the existing system, each client spawns a lockfile instance over SSH, and locks are acquired opportunistically. In contrast, this system uses a FIFO queue (with support for priority if that is needed in the future, but this is currently not used anywhere). This allows for 'fairer' waiting times, reducing tail waiting times.

Ease of administration

This system stores timestamps of when a job was created, when it acquires a machine, when it releases a machine. This is rather useful, for example: the total time a user or job has used the machine could be accessed. The server process itself is stateless, all state is stored in a SQLite database. The HTTP API offers a much richer set of data to use with dashboards etc.

Additionally, this system opens the potential for centralised management of machines, as the SQLite database already stores all relevant metadata about machines. In the existing system any changes to machine configurations require git commits to this repository, and then users have to git pull. This new system enables machines to be managed centrally from the SQLite database (using the CLI client), making it easier for admins to add, remove, or reconfigure machines on machine_queue.
This change will likely be in an upcoming PR to keep this one self-contained.

Breaking changes

  • Added dependencies on jq and machine-locks-client (the latter can be downloaded pre-built, built from source, or built with Nix)
  • Replacement of mq sem ... with pass-through to machine-locks-client
  • Replacement of machine-readable data format (now JSON and exposing all queue information)
  • Requirement to log in with Keycloak OAuth (some provisions will have to be made for external contributors)
  • By default jobs will timeout with a server-configurable default timeout (currently 2 hours), however this will need to be overridable including having no timeout.

Correctness

The change to machine_queue itself is rather trivial, its correctness is largely contingent to the correctness of components in machine-locks.

Now that acquiring locks involves creating a job in a FIFO queue it is important that such jobs are removed from the queue if terminated while waiting for a lock, or if something fails in this time. machine-locks-client itself handles this cancellation, in the same way that lockfile currently receives a SIGHUP if the connection is terminated while waiting on a lock. The trap for unlocking is retained, and unlocking is still idempotent as before.

Unlocking and advancing the queue are done on the server within automatic SQLite transactions (every SQLite statement is also an implicit transaction which subqueries execute within), that is that they are atomic. The query is also designed such that these operations are idempotent: if executed multiple times it will not skip a job.

Finally, the server handles cases where a job times out while a client is waiting for it to be acquired. This is extremely unlikely and can only happen if a client disappears for a while and starts polling again. In this case, a job timed out response is sent and the acquisition fails. If this case was not handled, the client would simply hang.

Before merge

  • Replace all file locking functions with invocations to machine-locks-client
  • Allow disabling lock timeout
  • Add authentication to machine-locks
  • Update MQ documentation
  • CI to pre-build releases of machine-locks-client for easier installation
  • Stress test machine-locks

Signed-off-by: debater-coder <hamzah@syedahmed.net>
Comment thread README.md Resolved
@lsf37

lsf37 commented Nov 24, 2026

Copy link
Copy Markdown
Member

Please clean up this PR so it is reviewable and a logical self-contained change, and explain what the change is, why it is being made, and why it is correct. This is critical infrastructure for the seL4 tests. Opening a PR with a random checkbox list and no explanation is not Ok.

For instance, there seems to be nix stuff in this PR. What for? If this needs a specific environment for development or even use and doesn't work properly in a generic context, then call this out and argue why that is Ok.

@debater-coder
debater-coder marked this pull request as draft November 24, 2026 10:03
@debater-coder

debater-coder commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Sorry, I should have marked this as a draft. I will add a lot more clarification.

As for the nix stuff: this new implementation requires a client binary. I have already packaged this with Nix but there will also be a pre-built binary built in CI as well as of course the option to build from source. This is what I was referring to in updating the documentation.

@debater-coder debater-coder changed the title Integrate with machine-locks-client Replace file locks with invocations to a centralised queue server over HTTP Nov 24, 2026
Signed-off-by: debater-coder <hamzah@syedahmed.net>
Signed-off-by: debater-coder <hamzah@syedahmed.net>
@debater-coder

Copy link
Copy Markdown
Author

Hi,
Thank you for your feedback and review.

I will be getting review from my supervisors in au-ts#1 first. We will be testing with a limited subset of machine_queue machines that are not used by CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants