#632 datamanager -- attempt to use closed file

Reporter silva
Owner MattJ
Stars ★ (1)  
  • Milestone-0.9
  • Priority-Medium
  • Type-Defect
  • Status-Fixed
  1. silva on

    For some reason my Prosody installation is suddenly unable to write to the files in /var/lib/prosody/<virtual host>/{accounts, roster,...}. In my prosody.cfg.lua, I have authentication set to "internal_hashed" and storage set to "internal". The error occurrs, when atmoic_store in datamanager.lua is called. It does this: f, msg = io_open(scratch, "w"); if not f then break end ok, msg = f:write(data); if not ok then break end ok, msg = f:close(); if not ok then break end f:close() crashes with 'attempt to use a closed file'.

  2. MattJ on

    Hi, thanks for the report! Any chance you could provide debug logs leading up to this issue? Can you tell us the Prosody version you have? (the output of `prosodyctl about` is useful).`

    • owner MattJ
  3. Zash on

    If it fails to flush the data, which it does in close(), it would attempt to close the file again in the cleanup section. This would produce a traceback. I guess this can happen if you run out of disk space.

  4. silva on

    Good call Zash! I have Prosody running on a Raspberry Pi and the SD card was indeed full. After moving Prosody's data and source directory to an external HDD and changing the paths in /usr/bin/prosodyctl to point to these I was able to get everything running again. I had to create a symlink to /usr/bin, though, because prosodyctl starts prosody with a relative path: /usr/lib/prosody/../../bin/prosody. Maybe this can be changed to use an absolute path.

  5. Zash on

    Minimal patch that should fix this: diff -r 01bd0ac9cf0c util/datamanager.lua --- a/util/datamanager.lua Wed Jan 27 13:05:58 2016 +0000 +++ b/util/datamanager.lua Thu Feb 25 17:34:03 2016 +0100 @@ -152,6 +152,7 @@ local function atomic_store(filename, da if not ok then break end ok, msg = f:close(); + f = nil; -- no longer valid if not ok then break end return os_rename(scratch, filename); We could also add a separate f:flush() step or disable write buffering to catch write errors before closing. I think it's somewhat annoying of Lua to throw a hard error for attempting to close a closed file. Having it be a noop would be much nicer.

  6. Zash on

    Committed that as http://hg.prosody.im/0.9/rev/67ac4a0b6e50 and also http://hg.prosody.im/0.10/rev/5bf0ff3882aa which should be more clear We do need tests for how things behave when running out of space tho

    • tags Status-Fixed
  7. Zash on

    • tags Milestone-0.9

New comment