Merge main into integration/1.2 - #1844
Merged
Merged
Conversation
KeyStore.load and KeyStore.store do not close the streams they are given, so every load and store leaked a descriptor until the cleaner ran. On Windows that also kept the file locked. Opening a FileOutputStream on the KeyStore file was the worse problem: it truncates on open, so a store() that failed part way through left behind a KeyStore with no keys in it. Writes now go to a temporary file in the same directory and are moved into place, preserving the original file's POSIX permissions and following symlinks so an existing link is updated rather than replaced by a regular file. set() and remove() mutate the in-memory KeyStore before writing it out, so they now roll that mutation back when the write fails; otherwise memory and disk stay diverged for the life of the process. set() also picks up the null alias guard that contains(), get() and remove() already had, and getAlias is declared @nullable to match how its callers treat it. The tests open a second store over the same file, which is the only way to tell that anything reached disk; the inherited assertions all pass against the in-memory KeyStore alone.
The same unclosed-stream problem as KeyStoreCertificateStore. Both copies now use Path with Files.newInputStream/newOutputStream, matching the client-examples copy that already had the fix.
The setting could not have worked. Four separate defects, any one of which was enough on its own: The watch key was never reset, and a WatchKey stays signalled and is never queued again until it is. The watcher could therefore fire at most once, after which take() blocked forever. processWatchEvent compared the event context against the KeyStore path, but a directory watch reports a context relative to the watched directory while toAbsolutePath resolves against the working directory. Unless the KeyStore happened to sit in the working directory, the comparison never matched. Only ENTRY_MODIFY was registered. Replacing a file by renaming a temporary one over it arrives as a creation, so the safe way to update a KeyStore produced no event at all. This store now writes its own file that way. The reload itself only called loadEntries(), which re-queries the KeyStore already held in memory. Even if an event had arrived, the file was never re-read, so an externally renewed certificate could not have been seen. Reloading now reads into a new KeyStore and swaps it in only once it has loaded, so a file that is unreadable, or still being written, leaves the one in use untouched. Overflow events are treated as a change, since there is no way to tell what was dropped. Closing the store also threw ClosedWatchServiceException out of the watcher thread rather than ending it, so shutdown left an uncaught exception behind. The end-to-end test fails against the previous implementation, timing out after 30 seconds; it passes in well under a second here.
…nges Make watchForChanges actually reload the KeyStore
Conflicts: opc-ua-stack/stack-core/src/test/java/org/eclipse/milo/opcua/stack/core/security/KeyStoreCertificateStoreTest.java Both branches added tests to KeyStoreCertificateStoreTest. Kept main's newKeyStoreCertificateStore() helper and its tests, and re-applied the alias and initialize() tests from integration/1.2 on top.
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.
Brings
integration/1.2up to date withmain.Commits from main
a0170a1Write the KeyStore atomically and close its streams6dc726cClose KeyStore streams in the example loaders2b65449Make watchForChanges actually reload the KeyStore2cb1643Merge pull request Make watchForChanges actually reload the KeyStore #1842 from eclipse-milo/fix/keystore-watch-for-changesConflict resolution
One conflict, in
KeyStoreCertificateStoreTest. Both branches added tests to the same fileon top of a common base:
mainrefactorednewCertificateStore()into anewKeyStoreCertificateStore()helper andadded tests for atomic writes, reload, and the watch service.
integration/1.2added tests for the ECC default aliases and forinitialize()skippingunmanaged and missing preloaded aliases.
Kept main's structure and tests, re-applied integration/1.2's three tests on top, and unioned
the imports. Nothing was dropped from either side.
KeyStoreCertificateStoreitself merged cleanly: main's atomic-write and reload changes applyover integration/1.2's ECC alias support without overlap.
Verification
mvn spotless:apply— no changesmvn clean compile— passesmvn -pl opc-ua-stack/stack-core test -Dtest=KeyStoreCertificateStoreTest— 13 tests, all pass