Conversation
…te import ends before its reader LDIFImportConfig(TemplateFile) starts the generator thread when it is built, and the thread stops only when its stream is closed. close() reached that stream only through the reader a backend takes, so an import which failed before a backend asked for the reader left the thread running for the life of the server. The config now closes the stream it created itself, and still leaves open a stream it was handed. ImportTask closes the config on the reject-file failure too: that return comes before the try whose finally closes it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1078
Problem
LDIFImportConfig(TemplateFile)starts the MakeLDIF generator thread as soon as it is built (MakeLDIFInputStream.newStartedInputStream()). That thread stops only when its stream is closed.LDIFImportConfig.close()reached the stream only throughreader, andreaderexists only once a backend callsgetReader(). A template import which failed before that leftMakeLDIF Input Stream Threadspinning inwriteEntry()for the life of the server, holding itsTemplateFileand its queue.Fix
LDIFImportConfigkeeps the stream it created itself in a separate field,ownedInputStream, andclose()closes it. A stream handed to the config throughLDIFImportConfig(InputStream)still belongs to the caller: the replication domain passes the stream a total update arrives on (LDAPReplicationDomain:5859), so the config does not close it. The template constructor delegates to that public constructor, soldifInputStreamalone cannot tell the two cases apart.ImportTasknow closes the config when the reject file cannot be opened. In [#1026] Close the import config on every path an import task can end on #1028 a close there was dead code, since no file is open on that road. For a template import, though, the generator is already running there, and that return comes before thetrywhosefinallycloses the config. Every other early road already goes through thatfinally.Tests
LDIFImportConfigTestCase(new):testClosingATemplateConfigWhichWasNeverReadStopsItsGenerator: 100 entries, well past the queue of ten, so the test first asserts the generator did not finish on its own.testClosingAConfigLeavesOpenTheStreamItWasHanded.TestImportAndExport.testTemplateImportWhichCannotOpenItsRejectFileStopsItsGenerator: a template import with a directory as the reject file. The generator is read from the task the scheduler kept, the same way [#1026] Close the import config on every path an import task can end on #1028 reads the config.Measured locally:
The generator is still running …LDIFImportConfigTestCase,TestImportAndExport,MakeLDIFTestCase,TestLDIFReaderclose()dropped from the reject catchTestImportAndExporttemplate case redclose()closesldifInputStreaminstead of the owned streamtestClosingAConfigLeavesOpenTheStreamItWasHandedredNotes on the issue text
import-ldif --templateFilefailing offline does return the shell: every such road returns 1, andImportLDIF.maincallsSystem.exiton a non-zero code. Those roads do skipimportConfig.close()(a skip-file failure leaks the reject writer, as [#1026] Close the import config on every path an import task can end on #1028 found for the task), but the process exits anyway. They are left out of this PR.Not in this PR
In
MakeLDIFInputStream, the fieldsclosed,allGeneratedandioExceptionare shared between threads withoutvolatile, andwriteEntry/getNextEntryswallowInterruptedException.