eventmesh icon indicating copy to clipboard operation
eventmesh copied to clipboard

Methods that continuously call WeakReference wrapper may throw an NPE

Open liutaohua opened this issue 4 years ago • 4 comments

All methods using WeakReference must check whether it is NULL after calling get().

image

liutaohua avatar Jul 19 '21 05:07 liutaohua

Yes, this does happen when the system gc occur, maybe we can use strong reference instead of weak reference.

ruanwenjun avatar Jul 19 '21 06:07 ruanwenjun

Yes, this does happen when the system gc occur, maybe we can use strong reference instead of weak reference.

I need to continue to understand the business logic in order to understand the author's intentions.

We can wait for more comments on this question.

liutaohua avatar Jul 19 '21 06:07 liutaohua

The weak reference of ClientGroupWrapper in Session.java is designed to avoid circular reference. Because ClientGroupWrapper contains the reference of Session, and Session contains the reference of ClientGroupWrapper.

You are right. When system GC occurs, weak references will be recycled, but if the strong reference of ClientGroupWrapper also exists, maybe it will not be a problem.

We can find strong reference in the clientGroupMap field of ClientSessionGroupMapping.java :

private ConcurrentHashMap<String, ClientGroupWrapper> clientGroupMap;

lrhkobe avatar Jul 19 '21 09:07 lrhkobe

It has been 90 days since the last activity on this issue. Apache EventMesh values the voices of the community. Please don't hesitate to share your latest insights on this matter at any time, as the community is more than willing to engage in discussions regarding the development and optimization directions of this feature.

If you feel that your issue has been resolved, please feel free to close it. Should you have any additional information to share, you are welcome to reopen this issue.

github-actions[bot] avatar Apr 23 '24 18:04 github-actions[bot]

@Pil0tXia, pls assigned this issue to me.

zhengkezhou1 avatar May 03 '24 07:05 zhengkezhou1

@zzzk1 OK

Pil0tXia avatar May 03 '24 10:05 Pil0tXia

Community member explained why the design is like this and why there is no need to worry about the potential weak reference problem (https://github.com/apache/eventmesh/issues/446#issuecomment-882404842). Could anyone explain why this viewpoint is not recognized and this issue must be fixed?

社区成员解释了为什么这样设计以及为什么不需要担心弱引用的潜在问题(https://github.com/apache/eventmesh/issues/446#issuecomment-882404842 ),谁能解释一下该观点不被认可、必须修复该issue的原因?

pandaapo avatar May 07 '24 13:05 pandaapo

Closed after https://github.com/apache/eventmesh/pull/4872#issuecomment-2155856899.

Pil0tXia avatar Jun 08 '24 20:06 Pil0tXia