@@ -215,6 +215,7 @@ FileHandle::TransferData::TransferData(int fd) : fd_(fd) {}
215215FileHandle::TransferData::~TransferData () {
216216 if (fd_ > 0 ) {
217217 uv_fs_t close_req;
218+ CHECK_NE (fd_, -1 );
218219 CHECK_EQ (0 , uv_fs_close (nullptr , &close_req, fd_, nullptr ));
219220 uv_fs_req_cleanup (&close_req);
220221 }
@@ -237,8 +238,9 @@ BaseObjectPtr<BaseObject> FileHandle::TransferData::Deserialize(
237238// JS during GC. If closing the fd fails at this point, a fatal exception
238239// will crash the process immediately.
239240inline void FileHandle::Close () {
240- if (closed_) return ;
241+ if (closed_ || closing_ ) return ;
241242 uv_fs_t req;
243+ CHECK_NE (fd_, -1 );
242244 int ret = uv_fs_close (env ()->event_loop (), &req, fd_, nullptr );
243245 uv_fs_req_cleanup (&req);
244246
@@ -384,6 +386,7 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
384386 close->Resolve ();
385387 }
386388 }};
389+ CHECK_NE (fd_, -1 );
387390 int ret = req->Dispatch (uv_fs_close, fd_, AfterClose);
388391 if (ret < 0 ) {
389392 req->Reject (UVException (isolate, ret, " close" ));
@@ -555,8 +558,13 @@ ShutdownWrap* FileHandle::CreateShutdownWrap(Local<Object> object) {
555558}
556559
557560int FileHandle::DoShutdown (ShutdownWrap* req_wrap) {
561+ if (closing_ || closed_) {
562+ req_wrap->Done (0 );
563+ return 1 ;
564+ }
558565 FileHandleCloseWrap* wrap = static_cast <FileHandleCloseWrap*>(req_wrap);
559566 closing_ = true ;
567+ CHECK_NE (fd_, -1 );
560568 wrap->Dispatch (uv_fs_close, fd_, uv_fs_callback_t {[](uv_fs_t * req) {
561569 FileHandleCloseWrap* wrap = static_cast <FileHandleCloseWrap*>(
562570 FileHandleCloseWrap::from_req (req));
0 commit comments