Adventures in Nodeland logo

Adventures in Nodeland

Subscribe
Archives
May 17, 2021

Async Iterators fun, a security vulnerability - Adventures in Nodeland - Issue #10

Hi Folks! Another week as passed and I’m going to list what I saw happening in Nodeland. First, we have an interesting puzzle with AsyncI terators, then a few bits of content, a (tough) security vulnerability with CSRF, and a job post that list Fastify as part of their stack! I really like this issue, I hope you can enjoy it as well.

I have always been a huge proponent of Async Iterators as a standard way to model streaming data. Async iterators are easier to understand and use compared to all the streams primitives on both the Web and Node.js. Even if they are simple to use and create, you still need to be aware of what is happening underneath.. as all I/O abstractions are leaky. Read up in this twitter thread:

Why is it relevant? The snippet above assumes that each async iterator could be completely disposed by the garbage collector. In Node.js, this is not the case if the async iterator wraps a native resource, such as a file descriptor, a Node.js Stream. Therefore, you need to manually dispose of files and sockets (and any other native resources).

Why was Node.js implemented in this way? The garbage collector is non-deterministic, therefore it’s not possible to rely on it to close native resources as soon as they are out of scope: if we supported this case, they could be left lingering in memory for a long time, leading to hard to debug “EMFILE” errors (the kernel error that is returned if the process cannot create more files).

You can also read about the Node.js core issue that spawned this discussion here:

Problems with cooperation between async generator and stream · Issue #38487 · nodejs/node · GitHub
Problems with cooperation between async generator and stream · Issue #38487 · nodejs/node · GitHub
Is your feature request related to a problem? Please describe. Consider this simple async generator which is supposed to merge output of two input generators: let merge = async function *(a, b) { yield *a; yield *b; }; When using with fi…
github.com

If you want to dig deep on how use EventEmitter and Streams inside async/ await, I recently did a talk about it: “The unsung hero story of Events, Streams and Promises”.

The Unsung Hero Story of Events, Streams and Promises - Matteo Collina
The Unsung Hero Story of Events, Streams and Promises - Matteo Collina

OpenHive.js

A few months back I had to opportunity to interview the fellow Node.js Technical Steering Committee member Danielle Adams.

Danielle Adams on Cloud Native Buildpacks by OpenHive.JS • A podcast on Anchor
Danielle Adams on Cloud Native Buildpacks by OpenHive.JS • A podcast on Anchor
Danielle is the Node.js Language Owner at Heroku, leading the Node platform for JavaScript and TypeScript developers. She is also a graduate student at New York University focusing on cybersecurity, a network director for Women Who Code in NYC, and an international public speaker. She is passionate about JavaScript and the well-being of the internet — as this discussion clearly demonstrates. Welcome back to OpenHive.JS.
https://github.com/nodejs/citgm https://buildpacks.io/ https://github.com/nodejs/node/blob/master/doc/guides/releases.md
anchor.fm
Danielle Adams on Cloud Native Buildpacks by OpenHive.JS • A podcast on Anchor
Danielle Adams on Cloud Native Buildpacks by OpenHive.JS • A podcast on Anchor
Danielle is the Node.js Language Owner at Heroku, leading the Node platform for JavaScript and TypeScript developers. She is also a graduate student at New York University focusing on cybersecurity, a network director for Women Who Code in NYC, and an international public speaker. She is passionate about JavaScript and the well-being of the internet — as this discussion clearly demonstrates. Welcome back to OpenHive.JS.
https://github.com/nodejs/citgm https://buildpacks.io/ https://github.com/nodejs/node/blob/master/doc/guides/releases.md
anchor.fm

Fastify

Fastify made the news recently when it became part of the standard templates of Glitch. The key reason? It’s plugin system. Read mode at:

A closer look at the new Glitch starter apps — Glitch Blog
A closer look at the new Glitch starter apps — Glitch Blog
From idea to code in seconds, build and learn alongside the most creative coders on the Web
blog.glitch.com

I have recently released as fix a for a long-time security vulnerability in fastify-csrf when using the technique called “double submit”. This vulnerability only affects users that are running fastify-csrf on several subdomains. Read more.

Lack of protection against cookie tossing attacks in fastify-csrf · Advisory · fastify/fastify-csrf · GitHub
GitHub is where people build software. More than 65 million people use GitHub to discover, fork, and contribute to over 200 million projects.
github.com

To ESM or to not ESM?

We are 5 months in 2021, and the question that burns me the most is… when should I start migrating my modules to ESM? Should I? I think I should wait for the loaders to be out of experimental, however folks are asking for an ESM version of https://www.npmjs.com/package/fastq among others. What do you think I should do? I’m considering using a dual package:

ESM doesn't need to break the ecosystem - DEV Community
ESM doesn't need to break the ecosystem - DEV Community
tldr; ECMAScript modules do not need to represent a hard break for the JavaScript ecosystem. This pos… Tagged with javascript, npm, esm.
dev.to
ESM doesn't need to break the ecosystem - DEV Community
ESM doesn't need to break the ecosystem - DEV Community
tldr; ECMAScript modules do not need to represent a hard break for the JavaScript ecosystem. This pos… Tagged with javascript, npm, esm.
dev.to

Jobs

This week I am trying a new experiment, sharing a job offer from a company that is looking for an engineer to work on a Fastify backend. My friend Ahmad Nassri is CTO at #paid - a platform that sits at the intersection of creator and brand collaboration. They are looking for a full stack engineer to build their Fastify application!

#paid - Senior Full-Stack Developer
Work with a team of developers, product managers, and designers who help each other solve problems across all functions. Employ best practices in development, security, accessibility and design to achieve the highest quality of service for our customers.
We use a range of technologies to get the job done: JavaScript and Node.js coupled with Fastify, OpenAPI Spec, React, and other libraries to provide a modern, easy-to-use Javascript toolchain that powers our platform.
jobs.lever.co

Thanks

That’s all for this week! As usual, I would not be writing this if it wasn’t for you - keep your feedbacks coming, open issues and contribute back to Node.js!

Don't miss what's next. Subscribe to Adventures in Nodeland:
GitHub X YouTube LinkedIn