Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v17.0.1 & v16.13.0 udp dgram health check bug in cluster model #40671

Closed
introspection3 opened this issue Oct 31, 2021 · 3 comments · Fixed by #43709
Closed

v17.0.1 & v16.13.0 udp dgram health check bug in cluster model #40671

introspection3 opened this issue Oct 31, 2021 · 3 comments · Fixed by #43709
Labels
dgram Issues and PRs related to the dgram subsystem / UDP.

Comments

@introspection3
Copy link

introspection3 commented Oct 31, 2021

Version

v17.0.1 & v16.13.0

Platform

ubuntun 20 x64

Subsystem

dgram.js

What steps will reproduce the bug?

https://github.com/nodejs/node/blob/2413283f55ef429764c50c5460dfb04127d13e7a/lib/dgram.js
function healthCheck(socket) {
if (!socket[kStateSymbol].handle) {
// Error message from dgram_legacy.js.
throw new ERR_SOCKET_DGRAM_NOT_RUNNING();
}
}
// use this code below,I check whether the port is Unused,same code works fine in single process but
ocurrs error in cluster model. may in server.close

function isUdpPortUnusedAsync(port) {
port = Number.parseInt(port);
logger.trace('isUdpPortUnusedAsync 1');
let p = new Promise((resolve, reject) => {
const server = dgram.createSocket('udp4');
server.on('error', (err) => {
logger.trace('isUdpPortUnusedAsync err' + err);
server.close();
resolve(false);
});

    server.on('listening', () => {
        logger.trace('isUdpPortUnusedAsync listening 1');
        server.close();
        logger.trace('isUdpPortUnusedAsync listening 2');
        resolve(true);

    });
    logger.trace('isUdpPortUnusedAsync 2');
    server.bind(port);
    logger.trace('isUdpPortUnusedAsync 3');
});
return p;

}

2021-10-31T19:21:56.193 ERROR default 927844 :==>Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
at new NodeError (node:internal/errors:371:5)
at healthCheck (node:dgram:909:11)
at Socket.address (node:dgram:760:3)
at Socket. (node:internal/cluster/child:115:25)
at Object.onceWrapper (node:events:509:28)
at Socket.emit (node:events:402:35)
at startListening (node:dgram:172:10)
at node:dgram:222:5
at shared (node:internal/cluster/child:149:3)
at Worker. (node:internal/cluster/child:106:7)
at process.onInternalMessage (node:internal/cluster/utils:49:5)
at process.emit (node:events:402:35)
at emit (node:internal/child_process:917:12)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
2021-10-31T19:21:56.193 ERROR default 927844 :==>Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
at new NodeError (node:internal/errors:371:5)
at healthCheck (node:dgram:909:11)
at Socket.address (node:dgram:760:3)
at Socket. (node:internal/cluster/child:115:25)
at Object.onceWrapper (node:events:509:28)
at Socket.emit (node:events:402:35)
at startListening (node:dgram:172:10)
at node:dgram:222:5
at shared (node:internal/cluster/child:149:3)
at Worker. (node:internal/cluster/child:106:7)
at process.onInternalMessage (node:internal/cluster/utils:49:5)
at process.emit (node:events:402:35)
at emit (node:internal/child_process:917:12)
at processTicksAndRejections (node:internal/process/task_queues:84:21) {
code: 'ERR_SOCKET_DGRAM_NOT_RUNNING'
}

How often does it reproduce? Is there a required condition?

every time

What is the expected behavior?

work fine in cluster model

What do you see instead?

No response

Additional information

if the port is unused,i will create a udpserver

@introspection3

This comment was marked as abuse.

@introspection3

This comment was marked as abuse.

@VoltrexKeyva VoltrexKeyva added the dgram Issues and PRs related to the dgram subsystem / UDP. label Oct 31, 2021
@introspection3 introspection3 changed the title udp health check bug in cluster model v17.0.1 & v16.13.0 udp dgram health check bug in cluster model Nov 1, 2021
@oyyd
Copy link
Contributor

oyyd commented Dec 24, 2021

A workaround is to set exclusive true, like:

const dgram = require('dgram')
const cluster = require('cluster')

if (cluster.isMaster) {
  cluster.fork()
} else {
  function isUdpPortUnusedAsync(port) {
    port = Number.parseInt(port);
    let p = new Promise((resolve, reject) => {
      const server = dgram.createSocket('udp4');
      server.on('error', (err) => {
        server.close();
        resolve(false);
      });

      server.on('listening', () => {
        server.close();
        resolve(true);
      });
      // server.bind(port);
      // A workaround is to set "exclusive" true
      server.bind({
        port,
        exclusive: true,
      })
    });
    return p;
  }


  isUdpPortUnusedAsync(3000).then(console.log)
}

nodejs-github-bot pushed a commit that referenced this issue Jul 11, 2022
This fixes closing dgram sockets right after binding in cluster
workers will throws `ERR_SOCKET_DGRAM_NOT_RUNNING` errors.

PR-URL: #43709
Fixes: #40671
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this issue Jul 12, 2022
This fixes closing dgram sockets right after binding in cluster
workers will throws `ERR_SOCKET_DGRAM_NOT_RUNNING` errors.

PR-URL: #43709
Fixes: #40671
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this issue Jul 20, 2022
This fixes closing dgram sockets right after binding in cluster
workers will throws `ERR_SOCKET_DGRAM_NOT_RUNNING` errors.

PR-URL: #43709
Fixes: #40671
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this issue Jul 31, 2022
This fixes closing dgram sockets right after binding in cluster
workers will throws `ERR_SOCKET_DGRAM_NOT_RUNNING` errors.

PR-URL: #43709
Fixes: #40671
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this issue Oct 10, 2022
This fixes closing dgram sockets right after binding in cluster
workers will throws `ERR_SOCKET_DGRAM_NOT_RUNNING` errors.

PR-URL: nodejs/node#43709
Fixes: nodejs/node#40671
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dgram Issues and PRs related to the dgram subsystem / UDP.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants