본문 바로가기
Q&A해결2026년 9월 9일2분 읽기

Rust async에서 'future cannot be sent between threads safely' 에러를 며칠째 못 잡습니다 ㅠㅠ

r
rust_hyun
조회 8댓글 4

tokio 쓰는데요, tokio::spawn 하는 순간 이 에러가 터집니다. 컴파일러 에러 메시지가 너무 길고 어려워서 며칠째 헤매는 중이에요.

error: future cannot be sent between threads safely
   --> src/handler.rs:42:5
    |
42  |     tokio::spawn(async move {
    |     ^^^^^^^^^^^^ future created by async block is not `Send`
    |
    = help: the trait `Send` is not implemented for
            `std::sync::MutexGuard<'_, State>`
note: future is not `Send` as this value is used across an await
   --> src/handler.rs:47:31
    |
45  |     let guard = state.lock().unwrap();
46  |     let id = guard.next_id();
47  |     let res = fetch(id).await;
    |                        ^^^^^ await occurs here, with `guard` still live

lock 잡고 값 하나 꺼내서 쓰는 것뿐인데 왜 Send가 안 된다는 건지... 락을 없앨 수도 없고 미치겠습니다. 어떻게 해결하나요?

댓글 0

아직 댓글이 없습니다.
Ctrl+Enter로 등록