Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

git hook: Connection to bitbucket.org closed by remote host.

A389216 November 29, 2022

In my project, I have a git pre-push hook that run test & lint on my code before push. It can take a lot of time (5 min for ex) and in that case, even is hook is successful, code is not pushed to Bitbucket with error "error: failed to push some refs to 'bitbucket.org:....". 

If I take a look to my hook logs, I see this log between 2 tests:

Connection to bitbucket.org closed by remote host.

Why connection to remote is open at start of the hook ? There is a way to change this behavior (I think Bitbucket socket is close in remote due to some timeout) ?

 

1 answer

1 accepted

1 vote
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 1, 2022

Hey @A389216 ,

Thank you for reaching out to Atlassian Community!

When you start a push, git has to connect to the remote host to check the refs on the server and determine what data can be pushed. Even though this is a pre-push hook, this connection still happens and is susceptible to timeout, as you have mentioned. Since it's part of git implementation, not Bitbucket specific, I'm not aware of a current option to disable it.

One suggestion would be for you to move the hook to a post-commit hook, so there would be no connection to the remote server in this case.

Another option is to implement a Pipeline build in your repository, so you push your code to a different branch than the main, and depending on the results of the pipeline you merge those changes into the main branch.

Hope that helps!

Thank you, @A389216 .

Patrik S

A389216 December 7, 2022

post-commit hook will run checks but it cannot prevent user from pushing some bad tested code... or I am missing something about post-commit hook ?

Further more, on our git flow, we rebase our feature branch with main branch to bring all new commit. pre-push allow to re-run test on updated code base.

We already have pipeline build to check code quality on remote side. But It's useful to retest before pushing, to reduce the wait time of pipeline run phase & notification.

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2022

Hello @A389216 ,

Essentially, any client-side hook can be bypassed by the person doing the git command, including post-commit and pre-push hooks. This is the reason why client-side hooks are not usually recommended if you want to enforce a policy in your repository because you can have the hook in place for all your developers, but you cannot really grant they were executed.

In this case, if you want to enforce a policy I would suggest implementing this policy as part of your pipeline build. In Bitbucket Cloud we also have Branch-Restriction that provides you closely control of which users or groups can write or merge to any branch.

That said, I'd also like to share that we have a feature request to support server-side hooks in Bitbucket Cloud, which you can find at the following link : 

We encourage you to add your vote and comment on that feature so our developers and product managers can better understand the interest. You can also add yourself as a watcher to receive first-hand updates.

Thank you, @A389216 .

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events