nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.46k stars 278 forks source link

UDP dgram error on receive message - EINVAL - Azure Web App/Azure Functions #4478

Closed teresahoes-klf closed 6 days ago

teresahoes-klf commented 1 week ago

Node.js Version

18.20.4

NPM Version

10.8.1

Operating System

windows

Subsystem

dgram

Description

Hello we recently started having issues with a UDP lookup to a sql server to get named instances within Azure Function Apps and Web apps (after and update to Azure Service Environment v3). We have an open ticket with Microsoft, but I was hoping to get some more information as to what might cause this error to happen so we might be able to narrow the focus with Microsoft.

This simple code as taken from the node documentation noted below produces the output shown below.

We are wondering what types of things could cause the "recvmsg EINVALat UDP.onMessage [as onmessage] (node:dgram:938:31)" error noted. We know via wireshark that the message reaches the sql server and returns the expected packet. But since we are unable to debug w/in the Azure environment, we cannot see what the returned message is (did it get modified somehow) or what is causing the error. We do not have this issue with regular windows VM's running the same code in azure.

thank you

Minimal Reproduction

_const localClientPort = 0; const sqlServer = await dnsLookup(sqlServerHostname, { family: 4 }); const sqlServerPort = 1434;

const server = dgram.createSocket('udp4');

server.on('error', (err) => {
    context.log(`Server error:\n${err.stack}`);
    server.close();
});
server.on('message', (msg, rinfo) => {
    context.log(`Message received: ${msg} from ${rinfo.address}:${rinfo.port}`);
});
server.on('listening', () => {
    const address = server.address();
    context.log(`Listening to: ${address.address}:${address.port}`);
});
server.on('connect', () => {
    const address = server.address();
    context.log(`Connected to: ${address.address}:${address.port}`);
});
//server.bind({port: localClientPort, exclusive: true});
 context.log('binding...');
server.bind(localClientPort, function (err, bytes) {
    if (err) {
        context.log(`Bind error:\n${err.stack}`);
        throw err;
    }
    context.log('Socket bound to: ' + sqlServer.address + ':' + sqlServerPort);

});

const message = Buffer.from([0x02]);

server.send(message, 0, message.length, sqlServerPort, sqlServer.address, function (err, bytes) {
    if (err) throw err;
    context.log('UDP message sent to ' + sqlServer.address + ':' + sqlServerPort);
});_

Output

2024-09-06T17:05:31.716 [Information] binding... 2024-09-06T17:05:31.716 [Information] Listening to: 0.0.0.0:0 2024-09-06T17:05:31.716 [Information] Socket bound to: 172.18.12.14:1434 2024-09-06T17:05:31.716 [Information] UDP message sent to 172.18.12.14:1434 2024-09-06T17:05:31.716 [Information] Server error:Error: recvmsg EINVALat UDP.onMessage [as onmessage] (node:dgram:938:31)

Before You Submit

RedYetiDev commented 1 week ago

Can you provide the Node.js debug output? (NODE_DEBUG=<subsystem|*> environment variable)

teresahoes-klf commented 1 week ago

Here is all the debug output around the call - (edited - i removed the timer output as that didnt seem relevant)

binding... Listening to: 0.0.0.0:0 Socket bound to: 172.18.12.14:1434 UDP message sent to 172.18.12.14:1434 Server error:Error: recvmsg EINVAL Error: recvmsg EINVAL at UDP.onMessage [as onmessage] (node:dgram:938:31) NET 6748: onconnection STREAM 6748: read 0 STREAM 6748: need readable false STREAM 6748: length less than watermark true STREAM 6748: do read NET 6748: _read - n 16384 isConnecting? false hasHandle? true NET 6748: Socket.handle.readStart HTTP 6748: SERVER new http connection STREAM 6748: resume STREAM 6748: resume true STREAM 6748: flow true STREAM 6748: read undefined STREAM 6748: need readable true STREAM 6748: length less than watermark true STREAM 6748: reading, ended or constructing false STREAM 6748: readableAddChunk null STREAM 6748: onEofChunk STREAM 6748: emitReadable false false STREAM 6748: emitReadable null HTTP 6748: SERVER socketOnParserExecute 1617 STREAM 6748: emitReadable false 0 true STREAM 6748: flow null HTTP 6748: write ret = true HTTP 6748: outgoing message end. STREAM 6748: onWriteComplete 0 undefined STREAM 6748: resume STREAM 6748: resume false STREAM 6748: read 0 STREAM 6748: endReadable false STREAM 6748: flow true STREAM 6748: read undefined STREAM 6748: endReadable false STREAM 6748: read 0 STREAM 6748: endReadable false STREAM 6748: endReadableNT false 0 STREAM 6748: endReadableNT true 0 STREAM 6748: endReadableNT true 0 NET 6748: _onTimeout NET 6748: destroy NET 6748: close NET 6748: close handle NET 6748: has server NET 6748: SERVER _emitCloseIfDrained NET 6748: SERVER handle? true connections? 0 NET 6748: emit close HTTP 6748: server socket close

teresahoes-klf commented 6 days ago

We received an update from MS - they have determined that they need to make a change in their network code for VNets in Azure Web apps to handle how node processes UDP calls.