octaltree / playwright-rust

Playwright port to Rust
298 stars 31 forks source link

Playwright dev branch no longer Send (thread safe) after this line of code. #38

Open randall-coding opened 1 year ago

randall-coding commented 1 year ago

Conditions: I'm running playwright (dev branch) in two parallel threads like so:

tokio::spawn(job_x); 
tokio::spawn(job_y); 

Error: Compilation error occurs saying Playwright is not Send.

std::marker::Send is not implemented for std::sync::MutexGuard<'_, playwright::"imp"::core::connection::Context> ./src/imp/playwright.rs:76:17

Diagnosis: I was able to narrow it down to this line of code std::mem::drop(ctx); in imp/playwright.rs

Partial Solution: After removing that line of code it will compile :+1: . However, though playwright works, it will hang indefinitely after I close the browser window and I have to kill the program manually. I'm not 100% sure it is from removing that line or not yet, but it seems likely.

hsyan2008 commented 1 year ago

Before:

let ctx = upgrade(&conn.context())?;                                                                                                                                                                                              
let ctx = ctx.lock().unwrap();                                                                                                                                                                                                 
let root = get_object!(ctx, &S::validate("").unwrap(), Root)?;                                                                                                                                                    
let root = upgrade(&root)?;                                                                                                                                                                                                       
std::mem::drop(ctx);

After:

let ctx = upgrade(&conn.context())?;                                                                                                                                                                                              
// let ctx = ctx.lock().unwrap();                                                                                                                                                                                                 
let root = get_object!(ctx.lock().unwrap(), &S::validate("").unwrap(), Root)?;                                                                                                                                                    
let root = upgrade(&root)?;                                                                                                                                                                                                       
// std::mem::drop(ctx);

and work fine!