usnistgov / h5wasm

A WebAssembly HDF5 reader/writer library
Other
87 stars 12 forks source link

Unable to open file #46

Open BraveenSri opened 1 year ago

BraveenSri commented 1 year ago

Hi When trying to create a file using new h5wasm.File(fileName, 'w'), occasionally following error happens.

**HDF5-DIAG: Error detected in HDF5 (1.12.1) thread 0:

000: /home/brian/dev/libhdf5-wasm/wasm_build/1_12_1/_deps/hdf5-src/src/H5F.c line 532 in H5Fcreate(): unable to create file

major: File accessibility minor: Unable to open file

001: /home/brian/dev/libhdf5-wasm/wasm_build/1_12_1/_deps/hdf5-src/src/H5VLcallback.c line 3282 in H5VL_file_create(): file create failed

major: Virtual Object Layer minor: Unable to create file

002: /home/brian/dev/libhdf5-wasm/wasm_build/1_12_1/_deps/hdf5-src/src/H5VLcallback.c line 3248 in H5VL__file_create(): file create failed

major: Virtual Object Layer minor: Unable to create file

003: /home/brian/dev/libhdf5-wasm/wasm_build/1_12_1/_deps/hdf5-src/src/H5VLnative_file.c line 63 in H5VL__native_file_create(): unable to create file

major: File accessibility minor: Unable to open file

004: /home/brian/dev/libhdf5-wasm/wasm_build/1_12_1/_deps/hdf5-src/src/H5Fint.c line 1858 in H5F_open(): unable to truncate a major: File accessibility

minor: Unable to open file**

Once I get the error, all requests are getting failed after that point with following error. RuntimeError: memory access out of bounds

The only thing that worked for me was trying to restart.

I wonder whether anyone can help me to fix this. Thanks!

Braveen.

Carnageous commented 1 year ago

First thing that comes to mind: did you wait for the filesystem to be ready (with await h5wasm.ready? This needs to be done before any read/write operations can be done.

BraveenSri commented 1 year ago

Hi @Carnageous, Thank you for your response Yes I did

Following is code segment

const h5wasm = await this.getH5wasm();
let writeFile = new h5wasm.File(fileData.name, 'w');
writeFile.create_dataset('signal', mergedEcgData, [ ecgSize ], '<d');
writeFile.create_dataset('annotation', mergedAnnotationData, [ annotationSize, annotationColumnCount ], '<q');
writeFile.create_attribute('summary', JSON.stringify(fileData.summary));
writeFile.close();
bmaranville commented 1 year ago

Can you tell me if this is happening for the first file you're trying to write after loading h5wasm, or does it happen later when adding more files?

Also it would help to know what's in the function this. getH5wasm()

BraveenSri commented 1 year ago

Hi @bmaranville, Thank you for your response

In my code, I am creating only one file per http request. After starting the nestjs application, this is not happening for the first request but for a random request sent after 2 or more requests.

Following is the this.getH5wasm() function. Sorry for not adding it initially.

async getH5wasm() {
    if (!this.h5wasm) {
        this.h5wasm = await getImport();
    }
    return this.h5wasm;
}
bmaranville commented 1 year ago

Sorry - can you also show what is in getImport() ? It's important to how the library is being initialized. I suspect there's another await statement needed in your code, but I won't be able to say for sure until I see how the library is being imported and initialized, right up until you use it.

BraveenSri commented 1 year ago

Sorry - can you also show what is in getImport() ? It's important to how the library is being initialized. I suspect there's another await statement needed in your code, but I won't be able to say for sure until I see how the library is being imported and initialized, right up until you use it.

async function getImport() {
  const h5wasm = await import('h5wasm');
  await h5wasm.ready;
  return h5wasm;
}
BraveenSri commented 1 year ago

Sorry - can you also show what is in getImport() ? It's important to how the library is being initialized. I suspect there's another await statement needed in your code, but I won't be able to say for sure until I see how the library is being imported and initialized, right up until you use it.

async function getImport() {
  const h5wasm = await import('h5wasm');
  await h5wasm.ready;
  return h5wasm;
}

@bmaranville could you please let me know is this what you asked

bmaranville commented 1 year ago

Sorry - I wasn't able to come up with a quick explanation of what's happening to you. The library initialization you're using seems fine. Without being able to run your code I'm not quite sure how to reproduce the error. There are other ways you can run into memory issues with wasm - are you opening extremely large files? How are you closing files when you are done with them? Are you overwriting a file with new contents when you open subsequent urls? ...