hhvm / hsl-experimental

Experimental features for the Hack Standard Library
MIT License
23 stars 10 forks source link

Cannot release a lock on a closed file, since it is already closed by the OS #160

Closed lexidor closed 4 years ago

lexidor commented 4 years ago

Is this intended behavior?

scope {
  $file = File\open_read_only(__DIR__.'foo.txt');
  using $file->tryLockx(File\LockType::SHARED);
  $file->close();
} // __dispose() releases an already released lock
Uncaught exception 'HH\Lib\_Private\_OS\ErrnoException' with message
'Errno 9: Bad file descriptor' in /path/to/vendor/hhvm/hsl-experimental/src/file/Lock.php:29
Stack trace:
#0 /path/to/vendor/hhvm/hsl-experimental/src/file/Lock.php(29): HH\Lib\_Private\_OS\flock()
#1 /path/to/src/start.hack(7): HH\Lib\File\Lock->__dispose()
...

According to the man pages, the lock is already released on file close, so it is releasing the same lock twice, causing an error.

$ man flock | grep -B 1 -A 1 closed
-u, --unlock
  Drop  a lock.  This is usually not required, since a lock is automatically dropped when the file is closed. 
  However, it may be required in special cases, for example if the enclosed command group may have forked
  a background process which should not be holding the lock.
fredemmott commented 4 years ago

nope, this is a bug - nice catch :)

fredemmott commented 4 years ago

well... missing catch :p