Skip to content

Commit fe7a343

Browse files
committed
Simplify Drop implementation for File
Do not try to spawn new tasks as this sometimes leads to deadlocks on 1-CPU machines, in particular VMs and old Android phones.
1 parent 798ce31 commit fe7a343

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/fs/file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::fs::{Metadata, Permissions};
1111
use crate::future;
1212
use crate::io::{self, Read, Seek, SeekFrom, Write};
1313
use crate::path::Path;
14-
use crate::prelude::*;
1514
use crate::task::{spawn_blocking, Context, Poll, Waker};
1615
use crate::utils::Context as _;
1716

@@ -315,7 +314,7 @@ impl Drop for File {
315314
// non-blocking fashion, but our only other option here is losing data remaining in the
316315
// write cache. Good task schedulers should be resilient to occasional blocking hiccups in
317316
// file destructors so we don't expect this to be a common problem in practice.
318-
let _ = futures_lite::future::block_on(self.flush());
317+
(&*self.file).flush().ok();
319318
}
320319
}
321320

@@ -883,6 +882,7 @@ impl LockGuard<State> {
883882
#[cfg(test)]
884883
mod tests {
885884
use super::*;
885+
use crate::prelude::*;
886886

887887
#[test]
888888
fn async_file_drop() {

0 commit comments

Comments
 (0)