morungos/wordnet

Unable to open ...

Closed this issue · 3 comments

I have very strange behaviour with wordnet.

After working a while it fails with error message

Unable to open ..

Filename can be different.
Files are available.
Permissions are OK.

It might be related to the second problem

I was using wordnet like in the following code

var WordNet = require("node-wordnet")
var wordnet = new WordNet()
function getwordnet(string, pos, relation, callback)
{ ... }

But the above code was working only for the first call of getwordnet, second call returns no results from wordnet. Then I changed it to the following

var WordNet = require("node-wordnet")
function getwordnet(string, pos, relation, callback)
{
var wordnet = new WordNet()
...
}

This was working for several fetches then fails with Unable to open ...

Can you help me to find the problem?

Hmmm. I suspect these are different issues. The second one looks very like a caching issue to me. If the values passed back from Wordnet are modified, then I think the results might be mangled, but I don't know what's going on inside getwordnet so it's hard to be certain. Essentially, the first shares a single Wordnet instance (and cache) and the second creates a new instance for each call (which might run out of file handles, but won't share a single cache).

The first issue looks like file handles aren't getting closed when needed. And there is an API call for that (wordiness.close()) but I don't actually document it. If you create multiple instances and never close them, that would probably trigger the first issue. I'll try to reproduce that.

So here's the plan so far. If the error is EMFILE, and it probably is, you can avoid it by (a) not creating too many Wordnet instances, and (b) closing them when no longer needed. They get transparently re-opened if needed. I'll also document close. This resolves #13.

I'd like to test EMFILE but I can't because mocha seems to add graceful-fs somewhere which patches the fs module so that EMFILE errors are never returned. So there won't be tests for #13 handling EMFILE errors.

On the other issue, I can't really do anything about the data issue unless you can tell me a bit more about the getwordnet. if it is a caching issue, and it probably is, using new WordNet({cache: false}) should resolve it. But I'd still like to know more, because I can make the caching a bit smarter if needed.

Closing. The improved error handling and #13 take care of most of this. If anything more specific shows, we can re-open or make a new issue of it.