-
Notifications
You must be signed in to change notification settings - Fork 10
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
Closing immediately after dialing successfully throws "writable end state is "writing" not "ready" #72
Comments
I'm having problems replicating this - here's what I'm running. It starts two nodes, registers a handler on one, dials the protocol handler from the other then shuts both nodes down. import { createLibp2p } from 'libp2p'
import { tcp } from '@libp2p/tcp'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
const PROTOCOL = '/test/protocol'
async function createNode () {
return createLibp2p({
transports: [
tcp()
],
connectionEncryption: [
noise()
],
streamMuxers: [
yamux()
],
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0'
]
},
connectionManager: {
minConnections: 0
}
})
}
console.info('start')
const [
node1,
node2
] = await Promise.all([
createNode(),
createNode()
])
await node2.handle(PROTOCOL, () => {})
console.info('dial')
await node1.dialProtocol(node2.getMultiaddrs(), PROTOCOL)
console.info('stop')
await node1.stop()
console.info('start')
await node1.start()
console.info('ok') package.json: {
"type": "module",
"dependencies": {
"@chainsafe/libp2p-noise": "^15.0.0",
"@chainsafe/libp2p-yamux": "^6.0.2",
"@libp2p/tcp": "^9.0.15",
"libp2p": "^1.2.3"
}
} |
I have not succesfully succeeded to reproduce with a minimal setup, starting from yours yet. But I have a failing test here, if I remove the delay. I will try out and come back if I figure out what kind of configuration gives this error. |
Ah, ok - my setup above was a bit wrong then, I've changed it to stop & start the dialing node as per the failing test. It still seems to work though. I've also checked out the peerbit repo, the test passes for me without the delay:
but I do get an (unrelated?) test failure with what looks like an internal Jest error:
|
Peerbit is a pretty neat project btw - you should PR the libp2p README to add the logo. |
That is interesting. Then it is something flaky going on depending on how fast the computer runs. But check this one import { createLibp2p } from 'libp2p'
import { tcp } from '@libp2p/tcp'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
export const delay = (ms: number) => {
return new Promise<void>((res, rej) => {
setTimeout(() => {
res();
}, ms);
});
};
it('test flaky', async () => {
async function createNode() {
const node = await createLibp2p<any>({
transports: [
tcp()
],
connectionEncryption: [
noise()
],
streamMuxers: [
yamux()
],
addresses: {
listen: [
'/ip4/127.0.0.1/tcp/0'
]
},
})
return node;
}
console.info('start')
const [
node1,
node2
] = await Promise.all([
createNode(),
createNode()
])
console.info('dial')
node2.dial(node1.getMultiaddrs()).catch((e) => { }) // dont wait here
await delay(5) // but put a little bit of delay
console.info('stop')
await node1.stop();
console.log("start again")
await node1.start()
console.log("stop all")
await Promise.all([node1, node2].map(x => x.stop()))
console.log("done")
}) When I run this on my computer with
the test never finishes (timeout at 60seconds)
It is maybe related to the issue |
Thank you! Appreciate it 🙏 Will do! |
is this still an issue? |
Was able to replicate and created a separate repo at https://github.com/tabcat/delay5 |
This seems isolated to the tcp transport. I was not able to replicate with webSockets swapped for tcp on the ws branch. Before I tried swapping yamux for mplex which also failed the delay 5 test. |
Was unable to replicate with the listed versions and the issue I found using the latest versions looks unrelated. |
I ran peerbit start and stop tests without the delay on latest version of master and they passed 5/5 times. This does not seem to be an issue anymore. Would you mind confirming? @marcus-pousette |
I migrated some test code previously using mplex to yamux and ran into issues for tests where I shutdown nodes immediately after dialing.
I get this error "writable end state is "writing" not "ready"
When this error is thrown read status is 'closing'
The "writeStatus" becomes 'writing' when the node is shutting down here here https://github.com/libp2p/js-libp2p/blob/c9ed1c7d62e9af974789eb753d6f8e3c6410df94/packages/utils/src/abstract-stream.ts#L155)
I am not expecting some uncaught errors to be thrown when I am shutting down a node after dialing and if there is a stream creation is in progress
Adding a delay after dialing before closing will stop the error to be thrown.
I am using libp2p (1.2.1) @libp2p/tcp (9.0.13), yamux (6.0.1)
Here is the callstack for when the error is throwing.
The text was updated successfully, but these errors were encountered: