Skip to content

DataConnection.on("close") listeners are not fired on device when closing the dataConnection #1336

@Pitouli

Description

@Pitouli

Please, check for existing issues to avoid duplicates.

  • No similar issues found.

What happened?

When I manually close the dataConnection by doing conn.close(), the listener that I have previously attached is not called ; it is called only when it is the remote peer that closes the connexion.

Note that it is especially visible in scenarios were the connexion has never been successfully openned (for example, you tried to connect to an unavailable peer, and then you close this failed connexion).

Note also that the connexion is correctly removed from peer.connexions after conn.close()

How can we reproduce the issue?

  1. Initiate a Peer
  2. Try to connect to an unavailable peer (connect to a random ID)
  3. You will see that the new connexion effectively appears in peer.connexions
  4. Add listeners on the connexion (in particular on "close" and "error")
  5. You will see that a "peer-unavailable" error is raised, but on the peer level and not the conn level
  6. Later, call conn.close()
  7. Check peer.connexion, the conn has been removed. But your listener has not been called

What do you expected to happen?

On step 5, I would like the error to be raised on the conn itself, and not the peer (but I think this issue is already discussed here: #1281 )

On step 7, I would like the listeners to be called.

Note that in the doc, it is said about the "close" event of the DataConnection:

Emitted when either you or the remote peer closes the data connection.

Environment setup

  • OS: Windows 10
  • Platform: React 18
  • Browser: Chrome

Is this a regression?

I do not know

Anything else?

I have made a workaround:

const connOnClose = (extendedClose = false) => {
  // The code I want to execute onClose
};
conn.on("close", connOnClose);
conn.extendedClose = () => {
  conn.close();
  connOnClose(true);
};

It does the trick, but I feel like it should work with the close() function directly

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions