xref: /third_party/node/test/parallel/test-dgram-bind-error-repeat.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst dgram = require('dgram');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/30209
61cb0ef41Sopenharmony_ci// No warning should be emitted when re-trying `.bind()` on UDP sockets
71cb0ef41Sopenharmony_ci// repeatedly.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciprocess.on('warning', common.mustNotCall());
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst reservePortSocket = dgram.createSocket('udp4');
121cb0ef41Sopenharmony_cireservePortSocket.bind(() => {
131cb0ef41Sopenharmony_ci  const { port } = reservePortSocket.address();
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  const newSocket = dgram.createSocket('udp4');
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  let errors = 0;
181cb0ef41Sopenharmony_ci  newSocket.on('error', common.mustCall(() => {
191cb0ef41Sopenharmony_ci    if (++errors < 20) {
201cb0ef41Sopenharmony_ci      newSocket.bind(port, common.mustNotCall());
211cb0ef41Sopenharmony_ci    } else {
221cb0ef41Sopenharmony_ci      newSocket.close();
231cb0ef41Sopenharmony_ci      reservePortSocket.close();
241cb0ef41Sopenharmony_ci    }
251cb0ef41Sopenharmony_ci  }, 20));
261cb0ef41Sopenharmony_ci  newSocket.bind(port, common.mustNotCall());
271cb0ef41Sopenharmony_ci});
28

Indexes created Thu Nov 07 10:32:03 CST 2024