Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Panic caused by nil pointer reference when calling dataproxy.(*client).OnClose #11584

Closed
2 tasks done
ABetterChoice opened this issue Dec 6, 2024 · 3 comments
Closed
2 tasks done
Assignees
Labels
type/bug Something is wrong
Milestone

Comments

@ABetterChoice
Copy link

ABetterChoice commented Dec 6, 2024

What happened

During the run, the program panicked with the following error:

image

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?

  • Yes, I am willing to submit a PR!

Code of Conduct

@ABetterChoice ABetterChoice added the type/bug Something is wrong label Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

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 🔍

@gosonzhang
Copy link
Contributor

@ABetterChoice , thanks and could you please submit a PR to fix this?

@dockerzhang 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
@dockerzhang dockerzhang added this to the 2.1.0 milestone Dec 6, 2024
@gunli
Copy link
Contributor

gunli commented Dec 6, 2024

This bug is fixed in #10674, please update to the latest version.
see https://github.com/apache/inlong/pull/10674/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is wrong
Projects
None yet
Development

No branches or pull requests

4 participants