Open begoon opened 1 week ago
I have bisected the releases and found that the last working release for me is 1.43.5
.
In 1.43.6
, the application starts crashing because of the error above.
Hello, can you explain how I can re-produce this bug?
What's the script in pdf-cli.ts?
I have isolated the code causing the crash.
I have attached a single file, called crash.ts
.
1.43.5 works okay with this file:
// deno upgrade --version 1.43.5
Downloading https://github.com/denoland/deno/releases/download/v1.43.5/deno-aarch64-apple-darwin.zip
Deno is upgrading to version 1.43.5
Archive: /var/folders/yt/48q9hkh95x7fg1ps8sr95wd40000gn/T/.tmpV6kgiH/deno.zip
inflating: deno
Upgraded successfully
// deno run -A src/pdf/crash.ts
Warning Sloppy imports are not recommended and have a negative impact on performance.
1.43.6 crashes.
// deno upgrade --version 1.43.6
Downloading https://github.com/denoland/deno/releases/download/v1.43.6/deno-aarch64-apple-darwin.zip
Deno is upgrading to version 1.43.6
Archive: /var/folders/yt/48q9hkh95x7fg1ps8sr95wd40000gn/T/.tmpi9CFkS/deno.zip
inflating: deno
Upgraded successfully
// deno run -A src/pdf/crash.ts
Warning Sloppy imports are not recommended and have a negative impact on performance.
thread 'tokio-runtime-worker' has overflowed its stack
fatal runtime error: stack overflow
zsh: abort deno run -A src/pdf/crash.ts
crash.ts
is attached.
crash.zip
I have checked on linux/amd64 too. The behaviour is the same. It crashes on 1.43.6, but 1.43.5 works.
deno --version
deno 1.43.6 (release, x86_64-unknown-linux-gnu)
v8 12.4.254.13
typescript 5.4.5
Hi @begoon, @dsherret, @bartlomieju
I've spent some time debugging the recent stack overflow issue we encountered while running our Deno script. After thorough investigation, I couldn't pinpoint any recursive asynchronous operations causing the problem. Instead, it appears that the issue stemmed from insufficient stack memory, exacerbated by recent updates in Deno's behavior complexity.
To address this, I explored increasing the stack memory allocation, which successfully resolved the issue on my WindowsPowerShell . Here's the command I used:
$env:RUST_MIN_STACK=9999999999 ; this for increase stack size try to increase the stack size until it work
see example:
for linux the equivalent command for environments would be export RUST_MIN_STACK=9999999999
Hi @begoon, @dsherret, @bartlomieju
I've spent some time debugging the recent stack overflow issue we encountered while running our Deno script. After thorough investigation, I couldn't pinpoint any recursive asynchronous operations causing the problem. Instead, it appears that the issue stemmed from insufficient stack memory, exacerbated by recent updates in Deno's behavior complexity.
To address this, I explored increasing the stack memory allocation, which successfully resolved the issue on my WindowsPowerShell . Here's the command I used:
$env:RUST_MIN_STACK=9999999999 ; this for increase stack size try to increase the stack size until it work
see example:
for linux the equivalent command for environments would be export RUST_MIN_STACK=9999999999
and it worked when I tried it on Ubuntu without rust.
@lucacasonato
Hello, my conclusion is that the issue is a memory issue, so what should we do? I believe we can add a flag to indicate the stack size of a thread, which would alleviate the issue if we didn't need to use env. RUST_MIN_STACK but env. RUST_MIN_STACK it resolves the issue
Hello! I looked into this and the cause is an overflow in swc
's resolver
transform, you can see this from the backtrace:
The immediate cause (in your code) is the very large string concatenation
"AAEAAAASAQAABAAgR0RFRrRCsIIAAir4AAACYkdQT1Or8IZpAAItXAAAZS5H" +
"U1VCeoGFdwACkowAABWQT1MvMpl2sYAAAhh4AAAAYGNtYXDG7lFtAAId8AAA" +
"BoJjdnQgBg4uPQACJ2gAAABaZnBnbYP7I6sAAiR0AAABvGdhc3AACAATAAIq" +
"7AAAAAxnbHlm1d+kywAAASwAAfh4aGRteHmPiKEAAhjYAAAFGGhlYWT9R9JX" +
"AAID5AAAADZoaGVhDUgS1wACGFQAAAAkaG10eN7XI9kAAgQcAAAUOGxvY2HG" +
// <continues for ~3864 more lines
That effectively creates one big expression with thousands of subexpressions (each +
creates a subexpression). When swc tries to visit this, it does one recursive function call per subexpression. Since there are so many subexpressions, that leads to a very deep call stack, which causes the stack overflow.
I'd recommend using escaped newlines or a template string instead of the string concatenation.
Escaped newlines (note the backslash at the end of each line, and the fact that the following line is not indented):
"AAEAAAASAQAABAAgR0RFRrRCsIIAAhNYAAACYkdQT1Or8IZpAAIVvAAAZS5H\
U1VCeoGFdwACeuwAABWQT1MvMpl2sdgAAgEYAAAAYGNtYXDG7lFtAAIGkAAA\
BoJjdnQgBg0uPQACEAgAAABaZnBnbYP7I6sAAg0UAAABvGdhc3AACAATAAIT\
TAAAAAxnbHlmVocNBQAAASwAAeEYaGRteI6hoLIAAgF4AAAFGGhlYWT9DdJS\
// etc
ADAAmACbADEA0ADQADUAAQABAEoAAQADAEoAVwCV"
Or a template string, with a helper to strip out the newlines and leading whitespace
const stripIndent = (s: string) => s.split("\n").map((l) => l.trimStart()).join("");
// later
stripIndent( `AAEAAAASAQAABAAgR0RFRrRCsIIAAhNYAAACYkdQT1Or8IZpAAIVvAAAZS5H
U1VCeoGFdwACeuwAABWQT1MvMpl2sdgAAgEYAAAAYGNtYXDG7lFtAAIGkAAA
BoJjdnQgBg0uPQACEAgAAABaZnBnbYP7I6sAAg0UAAABvGdhc3AACAATAAIT
TAAAAAxnbHlmVocNBQAAASwAAeEYaGRteI6hoLIAAgF4AAAFGGhlYWT9DdJS
ADAAmACbADEA0ADQADUAAQABAEoAAQADAEoAVwCV`)
Version: Deno 1.44.4
I have a complex CLI application to generate PDF's with pdfkit and a few extra libraries.
After the latest Deno update:
everything crashes no matter what with:
I'm puzzled about how to raise a bug report because I don't know how to supply a simple, reproducible test case.
Also, when I run this project AS IS but with Bun, it works as expected, with no crashes.
Any advice?
I have also realised that in the dockerfile, there is a version of Deno which I didn't upgrade. The application DOES work with that version:
I have downgraded my main CLI deno to 1.43.1, and... the crash is gone.
Something had been broken between 1.43.1 and 1.44.4.