SharedIndexWorkspaceImpl holding index lock indefinitely

Description

We've observed an issue in SharedIndexWorkspaceImpl that appears to be a bug.

Due to the nature of the bug (requires running two separate jvms) creating a test case would be difficult, however it is pretty simple to reason through.

within
SharedIndexWorkspaceImpl#getIndexWriter()
SharedIndexWorkspaceImpl#getIndexWriter(ErrorContextBuilder errorContextBuilder)

The openWritersUsers is incremented before an IndexWriter is successfully obtained.

We are seeing a scenario with two separate jvms writing to the same index where one process holds a lock long enough to cause a locktimeout and the second process fails to obtain an IndexWriter (yet it still increments the openWritersUsers). Subsequent writes from the second process create a lock which is never closed due to openWriterUsers being > 0.

Our fix:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 @Override public IndexWriter getIndexWriter() { synchronized ( lock ) { IndexWriter indexWriter = super.getIndexWriter(); if(indexWriter != null) { openWriterUsers++; } return indexWriter; } } public IndexWriter getIndexWriter(ErrorContextBuilder errorContextBuilder) { synchronized ( lock ) { IndexWriter indexWriter = super.getIndexWriter( errorContextBuilder ); if(indexWriter != null) { openWriterUsers++; } return indexWriter; } }

Thanks,
Tobias

Environment

hibernate-search 4.2.0.Final, any db

Status

Assignee

Sanne Grinovero

Reporter

Tobias Carson

Labels

Suitable for new contributors

Yes, likely

Pull Request

None

Feedback Requested

None

Time tracking

1h

Components

Fix versions

Affects versions

4.2.0.Final

Priority

Major