Skip to content
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

node 16 and aws-sdk #82

Closed
Ockejanssen opened this issue Jan 13, 2022 · 2 comments · Fixed by #88
Closed

node 16 and aws-sdk #82

Ockejanssen opened this issue Jan 13, 2022 · 2 comments · Fixed by #88

Comments

@Ockejanssen
Copy link

Ockejanssen commented Jan 13, 2022

When using node 16 the following code fails with
Error [ERR_MULTIPLE_CALLBACK]: Callback called multiple times
It does not happen on node 14.

It seems to be a problem with the highWaterMark. When it is low enough, it works.

const fs = require('fs');
const NodeClam = require('clamscan');

const {Writable} = require('stream');

class MyWritable extends Writable {
constructor(options) {
super(options);
}
_write(chunk, encoding, callback) {
// console.log("xxxxxx", arguments);
callback();
}
}

async function test() {
const source = fs.createReadStream('./README.md', {highWaterMark: 512});
const clamscan = await new NodeClam().init({clamdscan: {host: 'localhost', port: 3310}, debugMode: true});
const av = clamscan.passthrough();
av.on('finish', () => {console.log('--------------av finished');});
av.on('error', (error) => {console.log('--------------av error', error);});
av.on('scan-complete', (result) => {console.log('--------------av scan-complete', result);});
const mywritable = new MyWritable();
mywritable.on('error', (error) => {console.log('--------------mw error', error);});
mywritable.on('finish', () => {console.log('--------------mv finished');});
source.pipe(av).pipe(mywritable).on('finish', () => {console.log('all done', arguments);});
}

test();

@kylefarris
Copy link
Owner

I'm running low on bandwidth at the moment. I'm very open to pull requests. The source is pretty straightforward and well-documented. I'll have to address this sooner or later as we have production services that use clamscan that need to be updated to node 16.

But, yeah... any help would be great!

@ngraef
Copy link
Contributor

ngraef commented Feb 16, 2022

See discussion on nodejs/node#39535. This is caused by a behavior change in node 16 that tried to support Promise-returning stream implementation methods. That behavior was quickly deprecated because of the issues it caused. The error occurs when you try to return a Promise (async) and call the callback in the same function, like here in passthrough()'s Transform implementation:

clamscan/index.js

Line 1185 in c1d4f4c

async transform(chunk, encoding, cb) {

I'll open a PR with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants