Repository navigation
fix: scope native serial callbacks with MakeCallback - #243
DragonWork wants to merge 2 commits into
Conversation
932084a to
42279d6
Compare
42279d6 to
3fbc715
Compare
|
Project rip :( |
|
Maybe someone (or better a group of devs) fork it and maintain the project. Or the original codeowner comes back. Let‘s hope for the best. |
@serialport/bindings-cpp completes Windows reads and writes on its own thread and calls back into JavaScript from a uv_async handle with a plain napi Call. Since Node.js 26.4 nothing drains the microtask queue after such a call (nodejs/node#66158), so the promise the binding resolves continues only when some other macrotask runs. On Windows every GEADEV command waited for the next timer or console line: the USB app update timed out and fell back to the ROM downloader (BOOT), and a chatty app stalled on a console the host had stopped draining. Until the binding scopes its callbacks (serialport/bindings-cpp#243), loadSerialport wraps the native read/write so each callback queues a setImmediate, after which Node drains microtasks. It has to run before load-bindings.js promisifies them, so `gea doctor` loads serialport through it too. Writes on Node 26.7 went from 2 s timeouts to 0-1 ms; neon (3.9 MB) installs over a running reel through the app in 54 s, as on Node 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@serialport/bindings-cpp completes Windows reads and writes on its own thread and calls back into JavaScript from a uv_async handle with a plain napi Call. Since Node.js 26.4 nothing drains the microtask queue after such a call (nodejs/node#66158), so the promise the binding resolves continues only when some other macrotask runs. On Windows every GEADEV command waited for the next timer or console line: the USB app update timed out and fell back to the ROM downloader (BOOT), and a chatty app stalled on a console the host had stopped draining. Until the binding scopes its callbacks (serialport/bindings-cpp#243), loadSerialport wraps the native read/write so each callback queues a setImmediate, after which Node drains microtasks. It has to run before load-bindings.js promisifies them, so `gea doctor` loads serialport through it too. Writes on Node 26.7 went from 2 s timeouts to 0-1 ms; neon (3.9 MB) installs over a running reel through the app in 54 s, as on Node 24.
|
Getting this issue on macOS/Node26. Hope this project lives 🫡 |
|
@rickymohk I’ve been working on an alternative npm package, serialport-rs (GitHub), which has been running reliably in my projects for the past months. |
|
Thanks to @DragonWork and everyone who has investigated and contributed to this fix! I'm experiencing the same issue on Windows 11 with Node.js 26 and SerialPort 13. Serial I/O callbacks and Promise continuations can stall until another event-loop wakeup occurs. Everything works normally on Node.js 24, but on Node.js 26 I have to rely on a workaround to keep serial communication progressing. Since this PR addresses both the Unix poller and Windows read/write callbacks, could the maintainers please review it and consider moving it toward merging and releasing an updated This regression affects real-world serial communication applications and makes upgrading to Node.js 26 difficult. Having an official fix would be greatly appreciated. If additional testing or changes are needed before merging, it would also be helpful to know what's currently blocking the PR. Thanks again for maintaining SerialPort and for all the work on this fix! |
|
Unfortunately, this project appears to be effectively unmaintained at this point, and I wouldn't count on that changing anytime soon. The last SerialPort release dates back to December 2024. If you want to move forward with Node.js 26, you can either:
The latter is already seeing growing adoption, and we've recently had a contribution from @Azq2 as well (🫶🏻). Even Losant's Gateway Edge Agent, now part of SUSE, has adopted For the long term, I'd recommend migrating rather than relying on workarounds while waiting for an upstream fix that may never be released. |
Use
MakeCallback()with anAsyncContextfor Unix poller events and Windows read/write completions, including error paths. This prevents stalled nextTick/Promise continuations and preserves async context.Preserves @Azq2's original commit from #239, followed by explicit async contexts and Windows support. Listener ordering (#240) is unchanged.
Linux/Node 26.8.2: native timing/context check, build, typecheck and 74 existing tests pass (2 skipped). Windows and macOS runtime testing is still needed.