Error: ECONNREFUSED: Connection refused in Gitlab CI
See original GitHub issueHi
Running my tests through GItlab CI returns the following error Error: ECONNREFUSED: Connection
, but they all pass and work fine locally.
Please see my stackoverflow for more details thread
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
CI/CD: Error: ECONNREFUSED: Connection refused - GitLab
I have a nodejs, express api built using typescript and a mongo database. I am using mocha, chai and supertest to write my...
Read more >Error: ECONNREFUSED: Connection refused in Gitlab CI #488
Hi Running my tests through GItlab CI returns the following error Error: ECONNREFUSED: Connection, but they all pass and work fine locally.
Read more >GitLab CI with Postgres ERROR: connect ECONNREFUSED ...
So according to your error message I assume your code tries to reach the postgres database on localhost which works when you run...
Read more >connect ECONNREFUSED 127.0.0.1:5432 on Gitlab CI-docker
It seems like your npm command does not use the POSTGRES_HOST in variables section. Instead it uses 127.0.0.1 when connecting to postgres and...
Read more >Failed to connect to 127.0.0.1 port 80 - Super User
For a while already you need to use https for this to work, so setup your gitlab environment with ssl certificate.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@KayHS I hope the information below still is helpful.
Given the way you are initializing supertest (you are providing an http server instance), it will try to get the port information from the server instance. However the “hostname” information where the server was bound to, is determined by the supertest instance construction and fallbacks to 127.0.0.1 when it is not provided.
See:
Test is created without the host argument: https://github.com/visionmedia/supertest/blob/master/index.js#L25
Given that a server object was provided, the server address is computed: https://github.com/visionmedia/supertest/blob/master/lib/test.js#L36
Since no host was provided, it fallbacks to 127.0.0.1 https://github.com/visionmedia/supertest/blob/master/lib/test.js#L62
And that is what I think is happening. When you are in your local machine your test is probably binding to localhost, however in your CI seems like it is bounding it to a different host, but since supertest is not aware of that it is still trying to reach 127.0.0.1:
The solution in this case, is to either force your test server to be always bound to 127.0.0.1 or to use the
request('http://my-domain.com:port')
to construct supertest in a way that the server information gets ignored.I have this error too, even after binding using
request('http://localhost:5555');
. I still get CONNECTION REFUSED error on travisCI