You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Your code needs open a port (like to host a web page for your e2e tests) but it has to do some setup before the port can be opened. Some of that setup requires knowing the eventual port (like the test runner), so you find an open one early on and when it's time to open the port for real, you have a port number you want to use.
Problem
The problem is that between your search for an open port and actually opening that port another program did the same search, found that same port to be open, and is now using it. Your program crashes because the port was already in use. The happens frequently enough in your ci environment to drive you to excessive drinking.
Proposed Solution
// find an available port between (and including) 8080 and 9090.net.reservePort(8080,9090,function(err,port){// The port is now been opened by this process so no other process can try to open it.// The port number is stored in an array of "reserved ports".// Later on in the code...server.listen(port, ...);// When this process attempts to use that port, it will:// 1/ Find and remove it from the array of "reserved ports"// 2/ Close the port// 3/ Re-open the port using the passed in values.// Perhaps 2 and 3 must be done together in sync to avoid the port being stolen.});
Notes
Reserving a port should always be optional.
If the second number is not included then the developer is requesting a specific port to be reserved, such as net.reservePort(80, cb) to make sure this process can get port 80.
An error can happen if the port is not available, or when a range is specified, no ports were available in that range.
If the developer needs multiple ports than that person should call this function multiple times.
The upper bound of reserved ports is the same as open ports, because each reserved port must be open so that no other process can use the port.
The text was updated successfully, but these errors were encountered:
Lets say you are using a testing framework Like Protractor that has an option for a port.
You can use server.listen to find a port that is open, but you don't know if Protractor is going to open that port right away or later, after PhantomJS is up and running.
@dylang I think we are going to introduce uv_listen_stop in libuv eventually, let's keep this issue open and return back to it once it'll be completed.
Situation
Your code needs open a port (like to host a web page for your e2e tests) but it has to do some setup before the port can be opened. Some of that setup requires knowing the eventual port (like the test runner), so you find an open one early on and when it's time to open the port for real, you have a port number you want to use.
Problem
The problem is that between your search for an open port and actually opening that port another program did the same search, found that same port to be open, and is now using it. Your program crashes because the port was already in use. The happens frequently enough in your ci environment to drive you to excessive drinking.
Proposed Solution
Notes
net.reservePort(80, cb)
to make sure this process can get port 80.The text was updated successfully, but these errors were encountered: