kiwiirc / irc-framework

🛠️ A better IRC framework for node.js. For bots and full clients.
MIT License
180 stars 62 forks source link

Lines can be sent out-of-order #361

Open edfletcher opened 1 year ago

edfletcher commented 1 year ago

I initially filed this as an issue against my client, which uses this framework. At the time of filing that issue I'd encountered the bug multiple times, but only ever saw it reproduce when a very long input line was broken up before being sent. As I note in that issue description, I suspected it might be in this framework because I don't recall ever writing the code to break lines apart.

Upon further investigation I found that I do not break those lines apart (here & here are the call sites for IRC.Client functions that send messages, directly passing along the full message line).

That led me to dig into the IRC.Client code, and there I found clearly where the line break-up is taking place.

Digging in further I then came upon the eventual Connection.writeLine() function tasked with actually emitting lines onto the connected socket. This method calls the underlying net.Socket.write() method without checking the return value nor passing in a functional callback for notification of when the data has actually been written. Indeed, this would explain the behavior I saw.

edfletcher commented 1 year ago

I was able to create a test that can reproduce the issue and have a proposed fix for it behind a new serialize_writes option. I'll get that cleaned up and submitted as a PR here soon.

edfletcher commented 1 year ago

PR submitted: https://github.com/kiwiirc/irc-framework/pull/362