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:
   
   
![image](https://github.com/apache/eventmesh/assets/41445332/55a24f9e-1365-4b66-9345-e931f4222099)
   
   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:
   
   
![image](https://github.com/apache/eventmesh/assets/41445332/e611fe6a-fd0e-4940-9fb8-94b3d726c6ff)
   
   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:
   
   
![image](https://github.com/apache/eventmesh/assets/41445332/e489870d-9fb2-42ac-b17b-ef565af04ee3)
   
   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:
   
   
![image](https://github.com/apache/eventmesh/assets/41445332/b5d4240a-650a-491f-800f-f349703a6965)
   
   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:
   
   
![image](https://github.com/apache/eventmesh/assets/41445332/b5a98944-f7dc-4a6d-9504-db5ec30c9ecd)
   
   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]

Reply via email to