Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/asgi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ fn ensure_python_event_loop() -> Result<Arc<EventLoopHandle>, HandlerError> {
let weak_handle = PYTHON_EVENT_LOOP.get_or_init(|| RwLock::new(Weak::new()));

// Try to upgrade the weak reference
if let Some(handle) = weak_handle.read().unwrap().upgrade() {
if let Some(handle) = weak_handle.read()?.upgrade() {
return Ok(handle);
}

// Need write lock to create new handle
let mut guard = weak_handle.write().unwrap();
let mut guard = weak_handle.write()?;

// Double-check in case another thread created it
if let Some(handle) = guard.upgrade() {
Expand Down
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#![warn(clippy::dbg_macro, clippy::print_stdout)]
#![warn(missing_docs)]

use std::ffi::c_char;
#[cfg(feature = "napi-support")]
use std::sync::Arc;
use std::{ffi::c_char, sync::Arc};

#[cfg(feature = "napi-support")]
use http_handler::napi::{Request as NapiRequest, Response as NapiResponse};
Expand Down Expand Up @@ -345,6 +344,16 @@ pub enum HandlerError {
/// Error when PYTHON_NODE_WORKERS is invalid
#[error("Invalid PYTHON_NODE_WORKERS count: {0}")]
InvalidWorkerCount(#[from] std::num::ParseIntError),

/// Error when a lock is poisoned
#[error("Lock poisoned: {0}")]
LockPoisoned(String),
}

impl<T> From<std::sync::PoisonError<T>> for HandlerError {
fn from(err: std::sync::PoisonError<T>) -> Self {
HandlerError::LockPoisoned(err.to_string())
}
}

#[cfg(feature = "napi-support")]
Expand Down
Loading