Uncaught (in promise) BadResource: Bad resource ID
NeKzor opened this issue · 4 comments
This bug currently crashes the whole process unless you prevent it with unhandledrejection
.
Minimal reproducible example:
import Logger from 'https://deno.land/x/logger@v1.1.2/logger.ts';
const logger = new Logger();
await logger.initFileLogger("log", {
rotate: true,
maxBytes: 100,
maxBackupCount: 7,
});
setInterval(() => {
try {
logger.info('a');
logger.info('a');
} catch (err) {
console.error(err);
}
});
Stacktrace:
error: Uncaught (in promise) BadResource: Bad resource ID
close(this.file.rid);
^
at Writable.close (https://deno.land/x/logger@v1.1.2/writable.ts:31:5)
at Writer.write (https://deno.land/x/logger@v1.1.2/writer.ts:46:16)
at Logger.write (https://deno.land/x/logger@v1.1.2/logger.ts:79:18)
at Logger.info (https://deno.land/x/logger@v1.1.2/logger.ts:42:12)
Deno version:
deno 1.34.3 (release, x86_64-unknown-linux-gnu)
v8 11.5.150.2
typescript 5.0.4
Unhandled promise:
Line 79 in 0ac21c9
Here is another unhandled promise:
Line 47 in 0ac21c9
Unrelated but this code here tries to await a sync function:
Line 90 in 0ac21c9
Can you submit a pull request to fix this bug.
What your recommended handling for this error ?
ignore or try stderr ?
or try stderror once, that always better.
So how exactly is this issue fixed? Did you even test it?
If you look closely there are two issues here:
1.) You are mixing async and sync code! Make everything async or make everything sync. My guess is that it was supposed to be sync because you designed the logging signature as void. Changing it to Promise is a big breaking change but now you did it anyway and you are still not awaiting every Promise correctly!
2.) The rid problem exists because of a different bug which probably happens because of the file rotation.
As of now there are too many flaws in this library starting with this potential DoS (as it happened on my server).
I already moved on to deno std. I don't see why anyone would use this library over std/log.
So how exactly is this issue fixed? Did you even test it?
If you look closely there are two issues here:
1.) You are mixing async and sync code! Make everything async or make everything sync. My guess is that it was supposed to be sync because you designed the logging signature as void. Changing it to Promise is a big breaking change but now you did it anyway and you are still not awaiting every Promise correctly!
2.) The rid problem exists because of a different bug which probably happens because of the file rotation.
As of now there are too many flaws in this library starting with this potential DoS (as it happened on my server). I already moved on to deno std. I don't see why anyone would use this library over std/log.
Welcome to use Deno Std instead of this library. I have not been working on JS and TS development for over five years, focusing on Go language-related work. The maintenance of this library is currently very limited, and I do not have the ability and energy to do this work well. It relies more on community pull requests.