ABetterChoice opened a new issue, #11584:
URL: https://github.com/apache/inlong/issues/11584

   ### What happened
   
   During the run, the program panicked with the following error:
   
   <img width="1770" alt="企业微信截图_a53279c8-4ff3-423a-aefa-f789e5271976" 
src="https://github.com/user-attachments/assets/d9fb6295-e042-4f11-84c2-20ff288e4d21";>
   
   
   ### What you expected to happen
   
   Problem details:
   
   From the stack trace information, we can see that in the 
dataproxy.(*client).OnClose method, c.metrics.incError is called, but c.metrics 
is nil at this time, which causes a panic of a nil pointer reference.
   
   Specific location:
   
   metrics.go:197: (*metrics).incError method is called, but the receiver 
metrics is nil.
   
   client.go:294: In the (*client).OnClose method, c.metrics.incError is called 
directly without checking whether c.metrics is nil.
   Possible reasons:
   
   The metrics object is not correctly assigned when the client is initialized, 
or is set to nil during operation.
   In the process of closing the connection, the validity of metrics is not 
checked.
   Suggested fix:
   
   Add nil check: In the OnClose method of client.go, before calling 
c.metrics.incError, add a check to see if c.metrics is nil
   
   `
   if c.metrics != nil {
       c.metrics.incError("OnClose")
   }
   `
   
   Ensure that metrics are initialized correctly: When creating a client 
instance, ensure that the metrics field is initialized correctly to avoid nil.
   
   Scope of impact:
   
   May cause the program to crash when handling network connection closure.
   Affects normal data transmission and connection management using dataproxy 
clients
   
   ### How to reproduce
   
   Reproduction steps:
   
   Use the dataproxy client to establish a connection and perform data 
transmission.
   In certain circumstances (such as network anomalies or active connection 
closure), the OnClose method is triggered.
   The program crashes and throws the above panic error.
   Expected results:
   
   The OnClose method can correctly handle the situation where metrics is nil 
without panic.
   The program can stably handle the closure of the connection to ensure the 
robustness of the system.
   
   ### Environment
   
   Environment information:
   
   Go version: Please fill in your Go version
   Operating system: Please fill in your operating system information
   Dependency version:
   github.com/apache/inlong/inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang 
Version: v0.0.0-20240703021055-57985782d0a0
   github.com/panjf2000/gnet/v2 Version: v2.5.2
   
   ### InLong version
   
   master
   
   ### InLong Component
   
   InLong DataProxy, InLong SDK
   
   ### Are you willing to submit PR?
   
   - [X] Yes, I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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: dev-unsubscr...@inlong.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to