user2448122
user2448122

Reputation: 335

git push with post-receive slow

My git push operation finishes in around 25-30 seconds, instead of (more-or-less) immediate return. I am using a quite long post-receive (bash) script that I`ve found here: https://raw.github.com/zma/usefulscripts/master/script/post-receive

Some details:

I did some testing and if the post-receive script contains around 70 lines that are all commented out (so the script does nothing), push has a delay around 5 seconds.

Is this normal? Or is there a way to speed up push? Or I must reduce the script size dramatically?

Update: It is important to mention that:

Upvotes: 1

Views: 1319

Answers (4)

VonC
VonC

Reputation: 1324757

The git hooks page clearly mentions about the post-receive hook:

This script can’t stop the push process, but the client doesn’t disconnect until it has completed; so, be careful when you try to do anything that may take a long time.

That means, in your case, you need to switch to an asynchronous approach (unless you can fix what takes time, like Sqeezer's answer, upvoted, seems to propose):

  • making your script write in a file what it is supposed to do (send email)
  • letting a cron job pick up on that file and perform the lengthy task every few minutes.

That way, the post-receive hook returns as fast as possible, not blocking the client (downstream repo from where the push was initiated)

Upvotes: 1

user2448122
user2448122

Reputation: 335

It turned out that the samba share was configured to not to use oplocks with the following options in the smb.conf:

  • oplock = No
  • level2 oplocks = No

Removing these entries from the share`s configuration reduced the delay of the post-receive execution to around 4-5 seconds, which is reasonable I think.

Upvotes: 1

user2448122
user2448122

Reputation: 335

An interesting follow up: I`ve tested the script on another PC and it is working fine. No delay at all. So there are some issues on my PC regarding how git processes remote scripts.

The remote repository is on a samba share. I took a wireshark traces with 2 scenarios:

  1. just executed cat <path_to_the_script>\post-receive command in the git bash
  2. did a real git push

Results (without too much technical details):

  1. Read AndX Request, FID: 0x228f, 1024 bytes at offset 0 (1024 bytes at time, always)
  2. Read AndX Request, FID: 0x21c9, 1 byte at offset 0 (1 byte, always)

Conclusion: git push command reads the post-receive script in 1 byte chunks

Upvotes: 2

Sqeezer
Sqeezer

Reputation: 1277

From the script description

# An example hook script to mail out commit update information.  This hook
# sends emails listing new revisions to the repository introduced by the
# change being reported.  The rule is that (for branch updates) each commit
# will appear on one email and one email only.

Then take a look at the bottom of the script. It says:

# Note: change the smtp server to yours
        cat $email_tmp_file | mailx -S smtp="smtp://smtp.cse.ust.hk" -s "$emailsubject" -r $senderemail $recipients 

I believe you haven't configured your smtp server, therefore your script is waiting for smtp.cse.ust.hk to connect and then just disconnects by timeout.

Upvotes: 1

Related Questions