You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(async()=>{constsockets=newArray(100).fill({ip: "10.10.10.10",port: 6881}).map(async({ ip, port })=>{returnawaitBun.connect({hostname: ip,port: port,socket: {data(socket,data){console.log("data");},open(socket){console.log("open");},close(socket){// console.log("SOCKET CLOSED");},drain(socket){// console.log("SOCKET DRAIN");},error(socket,error){console.log("PEER TCP ERROR: ",{ error });socket.end();},connectError(socket,error){console.log("CONNECT ERROR",{ error });socket.end();},end(socket){console.log("END");socket.end();},handshake(socket){// console.log("HANDSHAKE");// Bitfield message indicating that we have no pieces// const bitfieldMessage = Buffer.alloc(5);// bitfieldMessage.writeUInt32BE(1, 0); // Length prefix// bitfieldMessage.writeUInt8(5, 4); // Message ID for bitfield// socket.write(bitfieldMessage);},timeout(socket){socket.end();},},}).catch((e)=>{console.log({ e });returnnull;});});awaitPromise.all(sockets);console.log("finished");})();
What is the expected behavior?
1: Near identical code using "net" fails in same ways (so not exclusive to Bun TCP)
2: Running near identical code with NODE runtime using node:net succeeds (so NodeJS handles this fine)
3: Code runs incredibly slowly when real ip / ports are used 300 sockets may take 1hr to all timeout (in node this is several seconds)
4: ECONNREFUSED crashing the program seems impossible to catch either with try/catch or .catch
What do you see instead?
[On WSL] - the program just hangs.
[On Windows] - Crashes in uncatchable way when invalid ip/port is used. (ECONNREFUSED)
[On All OS ] - Seems to resolve sequentially timing out slowly when 100's of sockets are created to valid ip/ports
Additional information
Use case for us:
We help run and maintain the nodes on the bittorrent network we need to be able to connect to many peers over TCP to exchange information.
In Node we can create 100's of sockets to many peers and close them once we have the information we need, in Bun it looks like a single socket works but many sockets seems to not work.
The text was updated successfully, but these errors were encountered:
does this work better with the following change? having await in the .map feels at odds with later calling Promise.all which would then await in parallel for you.
Sorry that's just an artifact of pasting some code around to get a smaller example.
No this doesn't help, as mentioned in post title this also breaks in same way using net.createConnection which is NodeJS's TCP API supported in Bun. 1 Connection is fine, many connections stalls the program or fails. Removing await here does nothing. net.createConnection doesn't even have a Promise based API. Program runs fine using Node (and swapping Bun related API's for their NodeJS counterpart).
This is preventing us from finishing our Bun migration.
What version of Bun is running?
1.1.6
What platform is your computer?
Microsoft Windows NT 10.0.19045.0 x64
What steps can reproduce the bug?
What is the expected behavior?
1: Near identical code using "net" fails in same ways (so not exclusive to Bun TCP)
2: Running near identical code with NODE runtime using node:net succeeds (so NodeJS handles this fine)
3: Code runs incredibly slowly when real ip / ports are used 300 sockets may take 1hr to all timeout (in node this is several seconds)
4:
ECONNREFUSED
crashing the program seems impossible to catch either with try/catch or .catchWhat do you see instead?
Additional information
Use case for us:
The text was updated successfully, but these errors were encountered: