Npm install from gitlab repo fails with "kex_exchange_identification: Connection closed by remote host" 9/10 times

I’ve got my own selfhosted instance of Gitlab, with a repo i include in a node.js project like this

{
  ...
  "dependencies": {
    "package-name": "git+ssh://git@GITSERVER/PATH/PROJECT.git#semver:~1.0.0",
    ...
  }
}

The problem im having is that sometimes it works perfectly fine and downloads the repo and the other git dependencies inside the repo, but 9/10 i have to run npm install multible times before it downloads and install all dependencies without erroring. The project has 8 or 10 other git dependencies it also have to download, all from my gitlab server. They are included the same way as the main package shown above.

The error i get is, and sometimes the it’s project 2 or 3 and sometimes it’s project 8 or 9 in the dependency list it fails on.

npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects clone ssh://git@GITSERVER/PATH/PROJECT-XYZ /home/msv/.npm/_cacache/tmp/git-cloneKNBhFm --recurse-submodules
npm ERR! Cloning into '/home/msv/.npm/_cacache/tmp/git-cloneKNBhFm'...
npm ERR! kex_exchange_identification: Connection closed by remote host
npm ERR! Connection closed by x.x.x.x port 22
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

Then you are propperly asking if i can conenct via SSH, and yes, yes i can.

ssh git@GITSERVER
PTY allocation request failed on channel 0
Welcome to GitLab, @MikkelSV!
Connection to GITSERVER closed.

If i just clone the repo with git clone i have no problems at all, it’s only though npm there is an issue. That sure sounds like a ratelimit… Well no, i’ve tried to disable the ratelimiting on gitlab and still no luck. The server is not bebind any proxy or something like that, that could mess with the connection.

At this point i’ve tried pretty much everything i can think of, even switching server host just to try it. (I had to move it anyways :P)

I’ve been having a very similar ongoing issue. I’m using vcstools to script a set of git pulls from our repos; on our university’s network it always gives the same error. After the first 6-7 pulls it will throw that kex_exchange error for all the other pulls and will keep rejecting all git ssh requests until it cools down for maybe like 10 seconds. We also dont see it when just doing clones and pulls from the cli. We’ve also never seen it from any other network, and we travel all over. It seemed like a rate limit for us too, but doesn’t make sense for it to be local network dependent. We have gitlab for education, so I guess no hope of getting a ticket to inspect logs from gitlab’s end…

Have you tried running your npm install on a different network?

I found the issue!
This can be fixed by changing this one line in the sshd_config file

MaxStartups 10:30:100

I’ve just upped the numbers a bit. (Currently 20:60:200)