You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "eye-gu (via GitHub)" <gi...@apache.org> on 2026/04/18 06:10:11 UTC
[PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
eye-gu opened a new pull request, #3298:
URL: https://github.com/apache/dubbo-go/pull/3298
### Description
Fixes # (issue)
### Checklist
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [ ] I have added tests that prove my fix is effective or that my feature works
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298#issuecomment-4275576438
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3298) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3298&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3298&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3298&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3298&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3298&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3298)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298#discussion_r3106167355
##########
protocol/jsonrpc/server.go:
##########
@@ -153,9 +153,10 @@ func (s *Server) handlePkg(conn net.Conn) {
if contentType != "application/json" && contentType != "application/json-rpc" {
setTimeout(conn, httpTimeout)
Review Comment:
`Content-Type` is compared using exact string equality. Requests like `application/json; charset=utf-8` (a very common form) will be treated as unsupported and return an error. Consider parsing/canonicalizing the media type (e.g., via `mime.ParseMediaType` and comparing the base type) before this check.
##########
protocol/jsonrpc/server.go:
##########
@@ -153,9 +153,10 @@ func (s *Server) handlePkg(conn net.Conn) {
if contentType != "application/json" && contentType != "application/json-rpc" {
setTimeout(conn, httpTimeout)
r.Header.Set("Content-Type", "text/plain")
- if errRsp := sendErrorResp(r.Header, []byte(perrors.WithStack(err).Error())); errRsp != nil {
+ errMsg := "unsupported content type: " + contentType
+ if errRsp := sendErrorResp(r.Header, []byte(errMsg)); errRsp != nil {
logger.Warnf("sendErrorResp(header:%#v, error:%v) = error:%s",
- r.Header, perrors.WithStack(err), errRsp)
+ r.Header, errMsg, errRsp)
}
return
Review Comment:
There are existing jsonrpc tests in this package, but this fix is currently untested. Please add a test that sends a non-JSON `Content-Type` request to the jsonrpc server and asserts it returns an error response without panicking (and ideally covers `application/json; charset=utf-8` if you adjust the parsing).
##########
protocol/jsonrpc/server.go:
##########
@@ -153,9 +153,10 @@ func (s *Server) handlePkg(conn net.Conn) {
if contentType != "application/json" && contentType != "application/json-rpc" {
setTimeout(conn, httpTimeout)
r.Header.Set("Content-Type", "text/plain")
- if errRsp := sendErrorResp(r.Header, []byte(perrors.WithStack(err).Error())); errRsp != nil {
+ errMsg := "unsupported content type: " + contentType
+ if errRsp := sendErrorResp(r.Header, []byte(errMsg)); errRsp != nil {
logger.Warnf("sendErrorResp(header:%#v, error:%v) = error:%s",
Review Comment:
This branch reports an unsupported request media type but `sendErrorResp` always uses HTTP 500. Consider returning `415 Unsupported Media Type` (or at least a 4xx) to avoid misclassifying a client error as a server error; this likely requires letting `sendErrorResp` accept a status code.
##########
protocol/jsonrpc/server.go:
##########
@@ -153,9 +153,10 @@ func (s *Server) handlePkg(conn net.Conn) {
if contentType != "application/json" && contentType != "application/json-rpc" {
setTimeout(conn, httpTimeout)
r.Header.Set("Content-Type", "text/plain")
Review Comment:
`r.Header.Set("Content-Type", "text/plain")` has no effect here because `sendErrorResp` unconditionally deletes `Content-Type` (and `Content-Length`) from the header map it reuses. If the intent is to return a `text/plain` error body, set the response `Content-Type` inside `sendErrorResp` (after the `Del` calls) or stop deleting it for this path.
```suggestion
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "eye-gu (via GitHub)" <gi...@apache.org>.
eye-gu commented on code in PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298#discussion_r3106561230
##########
protocol/jsonrpc/server.go:
##########
@@ -153,9 +153,10 @@ func (s *Server) handlePkg(conn net.Conn) {
if contentType != "application/json" && contentType != "application/json-rpc" {
Review Comment:
已修复
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298#issuecomment-4272995667
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3298?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0%` with `3 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 50.29%. Comparing base ([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ab47df3`](https://app.codecov.io/gh/apache/dubbo-go/commit/ab47df3bfabe441a8a747fa9e6e8c32832fa89aa?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 772 commits behind head on develop.
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3298?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [protocol/jsonrpc/server.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3298?src=pr&el=tree&filepath=protocol%2Fjsonrpc%2Fserver.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHJvdG9jb2wvanNvbnJwYy9zZXJ2ZXIuZ28=) | 0.00% | [3 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## develop #3298 +/- ##
===========================================
+ Coverage 46.76% 50.29% +3.52%
===========================================
Files 295 485 +190
Lines 17172 36317 +19145
===========================================
+ Hits 8031 18264 +10233
- Misses 8287 16600 +8313
- Partials 854 1453 +599
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/dubbo-go/pull/3298?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298#discussion_r3106165361
##########
protocol/jsonrpc/server.go:
##########
@@ -153,9 +153,10 @@ func (s *Server) handlePkg(conn net.Conn) {
if contentType != "application/json" && contentType != "application/json-rpc" {
Review Comment:
[P1] 这里还是用精确字符串比较 Content-Type,像 application/json; charset=utf-8 这种合法 JSON 请求仍然会被打到 unsupported 分支返回 500。这次修的是 nil panic,但没有把这个最常见的 header 变体一起兜住,也没补回归测试。建议先用 mime.ParseMediaType 解析主类型,再补一个带 charset 的请求用例。
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(jsonrpc): prevent nil pointer panic on unsupported content type [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3298:
URL: https://github.com/apache/dubbo-go/pull/3298#issuecomment-4272985858
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3298) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3298&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3298&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3298&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3298&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3298&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3298)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org