Pil0tXia commented on PR #4344: URL: https://github.com/apache/eventmesh/pull/4344#issuecomment-1673594283
I have resolved a new issue of `master` branch that occurred when calling the `updateWebHookConfig` endpoint, which resulted in an NPE:  I couldn't reproduce this NPE in debug mode. After adding a few simple logs, I found that the `fileWatchRegister` obtained an empty file. Each endpoint request triggered two file modification events, resulting in the first occurrence of an NPE and the second occurrence functioning normally:  Still, the issue is resolved by simply adding a delay before retrieving the events. With two endpoint requests, each request triggers only one file modification event:  Detailed logs of file locking, file acquisition, caching, and file modification events are shown. After the file is written, the second file modification event is triggered, which works normally:  You can clearly observe that after calling the `updateWebHookConfig` endpoint, a file modification event is triggered when creating a `FileOutputStream` in the `writeToFile` function. In this event, `fileWatchRegister` obtains an empty file before locking and writing to it, and then `cacheInit` is called to write `null` to `cacheWebHookConfig`, resulting in the NPE:  As seen, the NPE is thrown before the file locking is completed, so the `tryLock` method cannot be used to determine the file status. Previously, when inserting configurations, both ENTRY_CREATE and ENTRY_MODIFY events would occur, allowing differentiation based on the event type. However, when updating configurations, only an ENTRY_MODIFY event is generated, which is distinct from the former. Therefore, I used `CountDownLatch` to notify when the file write is completed and to wait for the notification before initializing the cache, which resolves the issue. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
