Skip to content

The allowHalfOpen doesn't seem to be working on the server #41

@CMCDragonkai

Description

@CMCDragonkai

I've created a server like:

    const utpSocket = UTP.createServer(
      async (utpConn) => {
        utpConn.on('close', () => {
          console.log('CLOSED ON REMOTE SIDE');
        });
      },
      {
        allowHalfOpen: false
      }
    );

Using the allowHalfOpen I'm expecting that the utpConn would be closed if the remote side has sent an end event. That is they closed their write side, ending my read side. Therefore I should have an automatic close of my write side, and that should trigger a close event.

However that's not what is happening. Instead I get a UTPCONNRESET error.

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Error: UTP_ECONNRESET
    at createUTPError (/home/cmcdragonkai/Projects/js-polykey/node_modules/utp-native/lib/connection.js:238:15)
    at Connection.Object.<anonymous>.Connection._onerror (/home/cmcdragonkai/Projects/js-polykey/node_modules/utp-native/lib/connection.js:175:16) {
  code: 'UTP_ECONNRESET',
  errno: 1
})
    at Connection.emit (events.js:304:17)
    at Connection.Object.<anonymous>.Connection._onclose (/home/cmcdragonkai/Projects/js-polykey/node_modules/utp-native/lib/connection.js:169:25) {
  code: 'ERR_UNHANDLED_ERROR',
  context: Error: UTP_ECONNRESET
      at createUTPError (/home/cmcdragonkai/Projects/js-polykey/node_modules/utp-native/lib/connection.js:238:15)
      at Connection.Object.<anonymous>.Connection._onerror (/home/cmcdragonkai/Projects/js-polykey/node_modules/utp-native/lib/connection.js:175:16) {
    code: 'UTP_ECONNRESET',
    errno: 1
  }
}

To actually ensure that my side is being closed if this occurs, I have to attach my own event handler to the end:

        utpConn.on('end', () => {
          utpConn.end();
        });

Only then does the connection actually close.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions