Closed achou11 closed 2 years ago
Had a read into this and a read through the source code of osm-p2p-syncfile. We need to ensure that we call syncfile.close()
within any error that is handled after the syncfile instance is created (https://github.com/digidem/mapeo-core/blob/ac/close-syncfile-after-invalid/sync.js#L475), although I'm not sure the state the syncfile is in after an error from syncfile.ready()
. We need to do this because the other errors will also leave the syncfile in a "damaged" state. I really don't like the way this works right now because it is really vulnerable to bugs, but we can patch this up for now and make sure we fix the way we sync to files in the future to make it more robust.
Had a read into this and a read through the source code of osm-p2p-syncfile. We need to ensure that we call
syncfile.close()
within any error that is handled after the syncfile instance is created (https://github.com/digidem/mapeo-core/blob/ac/close-syncfile-after-invalid/sync.js#L475), although I'm not sure the state the syncfile is in after an error fromsyncfile.ready()
. We need to do this because the other errors will also leave the syncfile in a "damaged" state. I really don't like the way this works right now because it is really vulnerable to bugs, but we can patch this up for now and make sure we fix the way we sync to files in the future to make it more robust.
Makes sense. Are you suggesting I add those patches to this PR, in addition to what I already added?
Makes sense. Are you suggesting I add those patches to this PR, in addition to what I already added?
Yes. I am proposing that syncfile.close()
is called within the error handler onerror
. However this will require a minor refactor to create a separate error handler because the current one is outside the scope of syncfile
. If not then we will just hit this same bug when a different error happens.
Yes. I am proposing that
syncfile.close()
is called within the error handleronerror
. However this will require a minor refactor to create a separate error handler because the current one is outside the scope ofsyncfile
. If not then we will just hit this same bug when a different error happens.
Attempted to clean up the implementation a bit so that the the file is closed whenever an error occurs. I ran the formatter on the file so the diff is a little bit hard to parse quickly, so I'd recommend just looking at https://github.com/digidem/mapeo-core/pull/132/commits/5bfd8d7ac926cc330426e40d77171eed53b145cd for the refactoring work
Looks good, just a small bug that needs fixed.
Optional callback
onClose
will not be called iferr
is truthy.
Spoke offline about this and this is desired behavior based on previous implementation, just needed some cleanup to make it clearer (see https://github.com/digidem/mapeo-core/pull/132/commits/8b497c37715aa3339c301c678a772273ccb65c44)
Addresses https://github.com/digidem/mapeo-desktop/issues/612
Preview (when patched on Mapeo Desktop):