diff --git a/src/sdk/namespace_fs.js b/src/sdk/namespace_fs.js index 51bf651d95..1f731540a4 100644 --- a/src/sdk/namespace_fs.js +++ b/src/sdk/namespace_fs.js @@ -1021,8 +1021,12 @@ class NamespaceFS { // NOTE: don't move this code after the open // this can lead to ENOENT failures due to file not exists when content size is 0 - // if entry is a directory object and its content size = 0 - return empty response - if (await this._is_empty_directory_content(file_path, fs_context, params)) return null; + // if entry is a directory object and its content size = 0 - close the stream and return empty response + if (await this._is_empty_directory_content(file_path, fs_context, params)) { + res.end(); + await stream_utils.wait_finished(res, { signal: object_sdk.abort_controller.signal }); + return null; + } file = await nb_native().fs.open( fs_context,