Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(node:68141) Warning: Closing file descriptor NNN on garbage collection #46

Closed
aradzie opened this issue Nov 2, 2020 · 10 comments
Closed

Comments

@aradzie
Copy link

aradzie commented Nov 2, 2020

This warning appears when I am trying to read exif data from a large collection of files. It seems like Exifr does not close file handles.

Example code:

await exifr.parse("filename.jpeg", true)
@boxymoron
Copy link

boxymoron commented Dec 28, 2020

I am experiencing the same when parsing a PNG file. The error is 'Error: Unknown file format' followed by 'Warning: Closing file descriptor 35 on garbage collection'

@adhamu
Copy link

adhamu commented Mar 23, 2021

Is there any update on this?

For reference, I am using the code like so on Node v14.15.5

const getFileModifiedTime = (file: string): Date => {
  const stats = statSync(file)

  return stats.mtime
}

export const getModifiedTime = async (file: string): Promise<Date> => {
  try {
    const output = await exifr.parse(file)

    return output?.DateTimeOriginal ?? getFileModifiedTime(file)
  } catch {
    return getFileModifiedTime(file)
  }
}

Which gives warnings like below:

(node:3306326) Warning: Closing file descriptor 196 on garbage collection
(Use node --trace-warnings ... to show where the warning was created)
(node:3306326) [DEP0137] DeprecationWarning: Closing a FileHandle object on garbage collection is deprecated. Please close FileHandle objects explicitly using FileHandle.prototype.close(). In the future, an error will be thrown if a file descriptor is closed during garbage collection.

This does happen, as @boxymoron says, when a PNG is parsed. Logging out the error in the catch gives the Unknown file format message already mentioned

@MikeKovarik
Copy link
Owner

Hello. Thanks for reaching out.
I'm sorry for responding late. As always, I can only find a few hours throughout the week to work on my projects and I'm currently occupied by finding a new job and PR #57.

Thanks for providing the info. @adhamu I suppose you call the getModifiedTime() method on a large ammount of files all at once, right?

I'm currently working on the code responsible for opening (and apparently not closing) files in PR #57 . But I can't assure it'll fix the problem.

@adhamu
Copy link

adhamu commented Mar 24, 2021

Thanks @MikeKovarik.

I have run this code against 100s of JPGs at a time and all works fine. It's only when a PNG (like a screenshot) is parsed, I get the warning.

Hopefully, your PR fixes it 👍

@MikeKovarik
Copy link
Owner

And exifr version are you using?

I tried running similar code to yours on a folder of about 170 png screenshots and I couldn't replicate it. Neither on windows nor wsl ubuntu. With the latest node 15 and current exifr 6.1.1.

As a matter of fact I remember these warnings occasionally occurring when running tests but it's no longer present there either.

@adhamu
Copy link

adhamu commented Mar 24, 2021

I'm using "exifr": "^6.1.1",

I'm struggling to reliably reproduce this myself.

@adhamu
Copy link

adhamu commented Mar 24, 2021

Ok found out why. I think when an unsupported file is attempted to be parsed, I get the warning.

I ran the code against a mix of file types including jpeg, png, gif, html, psd, and logged out the filename in the catch

image.gif [Error: Unknown file format]
image.psd [Error: Unknown file format]
(node:5033) Warning: Closing file descriptor 23 on garbage collection
(Use node --trace-warnings ... to show where the warning was created)
(node:5033) [DEP0137] DeprecationWarning: Closing a FileHandle object on garbage collection is deprecated. Please close FileHandle objects explicitly using FileHandle.prototype.close(). In the future, an error will be thrown if a file descriptor is closed during garbage collection.
(node:5033) Warning: Closing file descriptor 89 on garbage collection
image.html [Error: Unknown file format]
image-2.html [Error: Unknown file format]

@MikeKovarik
Copy link
Owner

Aaaaah :D so that's what's happening.
It's somewhere between a bug and not-a-bug but I'll fix it. I was about to release new minor version. Gues it'll have to wait a few more minutes :D

@adhamu
Copy link

adhamu commented Mar 24, 2021

Nice one. Cheers @MikeKovarik 👍

@MikeKovarik
Copy link
Owner

Closed with the latest commit. Thanks @adhamu for pin this down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants