You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the run, the program panicked with the following error:
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
Hello @ABetterChoice, thank you for opening your first issue in InLong 🧡 We will respond as soon as possible ⏳
If this is a bug report, please provide screenshots or error logs for us to reproduce your issue, so we can do our best to fix it.
If you have any questions in the meantime, you can also ask us on the InLong Discussions 🔍
@ABetterChoice , thanks and could you please submit a PR to fix this?
dockerzhang
changed the title
[Bug]Panic caused by nil pointer reference when calling dataproxy.(*client).OnClose
[Bug] Panic caused by nil pointer reference when calling dataproxy.(*client).OnClose
Dec 6, 2024
What happened
During the run, the program panicked with the following error:
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?
Code of Conduct
The text was updated successfully, but these errors were encountered: