Skip to content

Invoke post-receive hook after committing the transaction

Sami Hiltunen requested to merge smh-post-receive-fix into master

post-receive hook is invoked after a repository has been written into. The newly written data should be accessible to the hook. As the post-receive hook is invoked by the RPC handler, the newly written data is not accessible to it with transactions. The transaction and the new changes it introduces are typically only committed after the RPC handler has finished. This creates a problem for the post-receive hook as the data should already be accessible through Gitaly's API but isn't as the transaction hasn't yet been committed.

Simple solution could be to defer the hook execution to happen after the transaction commits. This however is not feasible as the post-receive hook may send messages to the client via receive-pack if this is a push.

This commit solve the problem by committing the transaction in the post-receive hook before running the actual hook logic. This ensures the changes have been persisted before invoking the hook. As the data is committed, it will be readable by transactions that start later such as the ones that Rails uses to read the data needed for its post-receive logic. After we commit the transaction, we start another read-only transaction to run the post-receive hook in to ensure it still runs with transactional guarantees.

Closes Invoke post-receive hook after transaction commit (#5536 - closed)

Edited by Sami Hiltunen

Merge request reports

Loading