Ignore post-receive hook exit status
Summary
Emergency call with customer (
Merge requests were all failing with 'An error occurred while merging. Try again'
However, the change to to the target branch was still being made.
The root cause was that the customer had a post-receive hook which always returned exit 1.
I guess !3094 (merged): "hook: Stop transactions when post-receive and update hooks fail" introduced the detection of this.
Key question: does it make sense to surface post-receive hook failures to the client.
- In the case of merge requests, I don't think this is a good idea. It's not observable .. the MR just fails.
- Are there other times that post-receive will trigger, and surfacing a failure is desirable?
Steps to reproduce
Create a customer post-receive hook, eg:
#!/bin/bash
exit 1
Try to merge a change.
What is the current bug behavior?
Detecting the post-receive hook failure breaks the merge request.
What is the expected correct behavior?
UPDATE as per this comment: ignore the exit status from the hook.
post-receive
The post-receive hook runs after the entire process is completed and can be used to update other services or notify users. It takes the same stdin data as the pre-receive hook. Examples include emailing a list, notifying a continuous integration server, or updating a ticket-tracking system – you can even parse the commit messages to see if any tickets need to be opened, modified, or closed. This script can’t stop the push process, but the client doesn’t disconnect until it has completed, so be careful if you try to do anything that may take a long time.
Relevant logs and/or screenshots
This behaviour is described in gitlab#326466 (closed) though it's not known whether the cause is the same.
In the merge request, the approvals is logged:
The merge commit is created, and pings back to the MR.
However step is missing:
From the gitaly logs:
{
"error": "executing custom hooks: exit status 1",
"grpc.method": "PostReceiveHook",
"grpc.request.fullMethod": "/gitaly.HookService/PostReceiveHook",
"grpc.service": "gitaly.HookService",
"level": "warning",
"msg": "stopping transaction because post-receive hook failed",
"peer.address": "@",
"span.kind": "server",
"system": "grpc",
}
from the Rails application_json.log :
{
"severity": "ERROR",
"time": "2021-05-04T12:42:50.751Z",
"correlation_id": "01F4VPDZQ5FK0YPFAZRKNT5GRR",
"message": "MergeService ERROR: group/project!15261 - An error occurred while merging"
}



