git pull fails in 75% of cases when 20 attempts made at once

Issue

I have a central server and when I need to do a batch task I launch a number of AWS instances simultaneously. During startup they call git pull (master is the central server) to get their version of the codebase up to head, so I often have 20 (or many more) pull requests at once.

Recently the delta between the instance’s starting image and head has become fairly large, and now a large percentage of the instances will have the pull fail with:

ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.

I can alleviate the issue by staggering the launching of the instances and keeping their image closer to head, but I would like to solve this issue for good – any ideas?

Solution

You are hitting both MaxSessions and MaxStartups limits.
Edit your /etc/sshd_config to this values and it will work after you reload sshd config.

# The number of simultaneous git pull you have
MaxSessions 20  

# MaxStartups this tells when sshd will start dropping unauthencicated sessions (% drop)
# Values: When_to_start_dropping_sessions:initial_rate:max_unauthenticated_sessions
# Set to MaxSessions-2*MaxSession:10:HugeNumber (defaults to 10:30:100).

MaxStartups 40:10:200  

Answered By – Iñigo González

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published