When sending an UDP in a for-loop, Rust panics and the app crashes
for(const buffer of buffers){
listener.send(buffer, ...);
}
thread 'main' panicked at 'already borrowed: BorrowMutError', /rustc/4fb7144ed159f94491249e86d5bbd033b5d60550\src\libcore\cell.rs:878:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace`
Sending an UDP in a for-loop, but awaiting, works
for(const buffer of buffers){
await listener.send(buffer, ...);
}
Is this using version 1.0.5 ?
Can you provide some concrete example script which demonstrates this error?
@ry I debugged it and found this
Example code that breaks:
const listener = Deno.listenDatagram({
port: 8080,
transport: "udp"
});
const encoder = new TextEncoder();
const buffer = encoder.encode('test data');
const buffers = [buffer, buffer];
for(const buffer of buffers){
listener.send(buffer, {
hostname: "127.0.0.1",
port: 8080,
transport: "udp"
});
}
Output:
thread 'main' panicked at 'already borrowed: BorrowMutError', /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd/src/libcore/cell.rs:878:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
At this borrow:
https://github.com/denoland/deno/blob/bad6f2b224a92e3bf5cdaf5f8cbc700cb0f9de04/cli/ops/net.rs#L213
It seems like a multi-threading issue. But I lack the knowledge of Rust to come up with a fix.
@pevers Thank you - I can repeat it now. I'm working on a fix.