Deno: 'already borrowed: BorrowMutError' when using std lib server with Unix listener

Created on 22 Apr 2020  路  3Comments  路  Source: denoland/deno

Deno 0.41, Mac 10.14.6

If I create a listener on a unix domain socket, and create a Server from that, Deno crashes the moment a client connects.

In the code below, there is a commented out section that allowed me to check that the lower level UDS stuff basically works, meaning that it's probably something in Server that's causing this.

import { Server } from "https://deno.land/std/http/server.ts";

let sock_path = Deno.args[Deno.args.length -1];

serve();

async function serve() {
    const listener = Deno.listen({ address: sock_path, transport: "unix" });

    /////////////// works:
    // let conn = await listener.accept()
    // let uint8 = new Uint8Array(2);
    // let r = await conn.read(uint8);
    // var string = new TextDecoder("utf-8").decode(uint8);
    // console.log( "read", r, string);

    ////////////////// crashes:
    const server = new Server(listener);
    for await (const request of server) {
        console.log("got a request")
    }
}
RUST_BACKTRACE=1 deno --reload --allow-write --allow-read ds-appspace-runner.ts sock.sock

I do this to connect to the socket:

nc -U sock.sock

And bam:

thread 'main' panicked at 'already borrowed: BorrowMutError', /private/tmp/rust-20200323-71040-kiw2y8/rustc-1.42.0-src/src/libcore/cell.rs:878:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
  10: <std::future::GenFuture<T> as core::future::future::Future>::poll
  11: <futures_util::future::try_future::map_ok::MapOk<Fut,F> as core::future::future::Future>::poll
  12: <futures_util::future::try_future::map_ok::MapOk<Fut,F> as core::future::future::Future>::poll
  13: <&mut S as futures_core::stream::Stream>::poll_next
  14: futures_util::stream::stream::StreamExt::poll_next_unpin
  15: <deno_core::isolate::Isolate as core::future::future::Future>::poll
  16: <deno_core::es_isolate::EsIsolate as core::future::future::Future>::poll
  17: <std::future::GenFuture<T> as core::future::future::Future>::poll
  18: std::thread::local::LocalKey<T>::with
  19: tokio::macros::scoped_tls::ScopedKey<T>::set
  20: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on
  21: tokio::runtime::context::enter
  22: deno::tokio_util::run_basic
  23: deno::main
  24: std::rt::lang_start::{{closure}}
  25: std::panicking::try::do_call
  26: __rust_maybe_catch_panic
  27: std::rt::lang_start_internal
  28: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This could be a dupe of #4511?

bug cli

All 3 comments

The error I get is the same, not sure how to reproduce it on my side... what I'm doing is processing high frequency WebSocket data (100ms between updates) and while doing that I log to the console each 1000 updates (basically outputting performance data), I always run into the same error after some arbitrary time (it seems):

thread 'main' panicked at 'already borrowed: BorrowMutError', /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libcore/cell.rs:867:31
stack backtrace:
   0:        0x1030ab935 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h24bb64d98a7e25d6
   1:        0x102d743ec - core::fmt::write::h8fdc9cddb01cd8b2
   2:        0x1030aaf49 - std::io::Write::write_fmt::hcc3030013983bab6
   3:        0x1030aa905 - std::panicking::default_hook::{{closure}}::h95817712c5ff0736
   4:        0x1030aa052 - std::panicking::rust_panic_with_hook::haf571858f996ac45
   5:        0x1030ae53a - rust_begin_unwind
   6:        0x103da826f - core::panicking::panic_fmt::h11676ba6a846d9f4
   7:        0x103da87d5 - core::option::expect_none_failed::h312e48bacb63d8ec
   8:        0x102be47e2 - core::cell::RefCell<T>::borrow_mut::he4cde6b6b24a70fb
   9:        0x102c3dcce - <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll::he4cd728c68aa5048
  10:        0x102c492b2 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2f0d226887e4163f
  11:        0x102b60c12 - <futures_util::future::future::Inspect<Fut,F> as core::future::future::Future>::poll::h689403808c6ba7d8
  12:        0x102d871bb - <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll::hdc0b967435fefa67
  13:        0x102d8b086 - <futures_util::stream::futures_unordered::FuturesUnordered<Fut> as futures_core::stream::Stream>::poll_next::h684f521d66f6e5b2
  14:        0x102d135f3 - <deno::worker::Worker as core::future::future::Future>::poll::h6a3e878a0a64cd5f
  15:        0x102c54a97 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h9709a5b4a26e0cc4
  16:        0x102c17d31 - tokio::runtime::Runtime::block_on::h8a30458e9651d36e
  17:        0x102d1eeac - deno::main::hd895b7a7adcfc7d5
  18:        0x1030c39e6 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd67e5532c4fc3d97
  19:        0x102d25f28 - main

I'll check if I still get the error when I completely disable any logging to the console and update this comment...

Using Deno v1.4.1

@exside could you provide a gist of your code? I'll try to fix this problem before the next release.

Tested this out again with 1.4.1 and the issue I had is now resolved (thank you!), so I am closing. I suggest opening another issue for the ws problem as it's likely unrelated.

Was this page helpful?
0 / 5 - 0 ratings