File tree Expand file tree Collapse file tree 1 file changed +19
-16
lines changed
packages/mongodb-memory-server-core/src/util Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -62,24 +62,27 @@ export class MongoBinary {
6262 const lock = await LockFile . lock ( lockfile ) ;
6363 log ( 'getDownloadPath: Download lock acquired' ) ;
6464
65- // check cache if it got already added to the cache
66- if ( ! this . cache . get ( version ) ) {
67- log ( `getDownloadPath: Adding version ${ version } to cache` ) ;
68- const downloader = new MongoBinaryDownload ( {
69- downloadDir,
70- platform,
71- arch,
72- version,
73- checkMD5,
74- } ) ;
75- this . cache . set ( version , await downloader . getMongodPath ( ) ) ;
65+ // this is to ensure that the lockfile gets removed in case of an error
66+ try {
67+ // check cache if it got already added to the cache
68+ if ( ! this . cache . has ( version ) ) {
69+ log ( `getDownloadPath: Adding version ${ version } to cache` ) ;
70+ const downloader = new MongoBinaryDownload ( {
71+ downloadDir,
72+ platform,
73+ arch,
74+ version,
75+ checkMD5,
76+ } ) ;
77+ this . cache . set ( version , await downloader . getMongodPath ( ) ) ;
78+ }
79+ } finally {
80+ log ( 'getDownloadPath: Removing Download lock' ) ;
81+ // remove lock
82+ await lock . unlock ( ) ;
83+ log ( 'getDownloadPath: Download lock removed' ) ;
7684 }
7785
78- log ( 'getDownloadPath: Removing Download lock' ) ;
79- // remove lock
80- await lock . unlock ( ) ;
81- log ( 'getDownloadPath: Download lock removed' ) ;
82-
8386 const cachePath = this . cache . get ( version ) ;
8487 // ensure that "path" exists, so the return type does not change
8588 assertion (
You can’t perform that action at this time.
0 commit comments