Why is Bitbucket Server listening on random ports?
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Question
You are noticing that Bitbucket is choosing two random ports to listen to on start-up, and are looking to gain information on what these ports are being used for, and if they can be configured to be set to a static value.
Answer
By default Bitbucket Server and Bitbucket Data Center opens two random ports for the following Git operations:
- Git transcoding, which helps deal with non-UTF-8 data in Git repositories
- Git hook callbacks into Bitbucket Server/Bitbucket Data Center
For this reason, these ports cannot be disabled. However, you can change the behavior from just choosing a random port to instead having them listen on a consistent port of your choosing.
This can be done by adding the following configuration values into your $BITBUCKET_HOME/shared/bitbucket.properties file, and making sure to replace 0 with the ports of your choice:
hook.callback.socket.port=0
plugin.bitbucket-git.transcode.socket.port=0
(For Stash, the transcode property is plugin.stash-scm-git.transcode.socket.port=0. If this is configured, it will automatically be rewritten for Bitbucket Server upon upgrading to any 4.x version.)
If the configured value is negative or zero (the default), a random port is used. Otherwise, the specific port is used.
Once this configuration has been made, the ports for these two services should listen on the ports you specify the next time that Bitbucket is restarted.
The ports chosen should generally be 1024 or higher, since low range ports typically require root access and Bitbucket Server/Stash should not be run as root.