Comments (4)
To replicate:
- run
go test -race
- replace sonic with encoding/json and then run
go test -race
Versions:
go version go1.16.5 darwin/amd64
file: main.go
package main
import (
"fmt"
"github.com/bytedance/sonic"
)
func main() {
fmt.Println("plain")
}
func ExtractJson(idx int, body interface{}) {
j := []byte(exampleJson[idx])
// REPLACE sonic WITH json
err := sonic.Unmarshal(j, &body)
if err != nil {
fmt.Println(err.Error())
return
}
}
var exampleJson1 = `{
"page_info": { "total_count": 1, "page_num": 1 },
"code": 0,
"data": [
{
"name": "dp-91b905d33f-5559868569-z8tvk",
"node_ip": "10.245.11.66",
"psm": "A.B.C",
"containers": [
{
"status": "Running",
"mem_usage_pct": 15.0,
"name": "dp-91b905d33f",
"cpu_usage_pct": 3.8
},
{
"status": "Running",
"mem_usage_pct": 13.0,
"name": "dp-91b905d33f",
"cpu_usage_pct": 2.1
}
]
}
],
"error": ""
}`
var exampleJson2 = `{
"page_info": { "total_count": 1, "page_num": 1 },
"code": 0,
"data": [
{
"name": "dp-91b905d33f-5559868569-z8tvk",
"psm": "P.Q.R",
"containers": [
{
"status": "Running",
"mem_usage_pct": 15.0,
"name": "dp-91b905d33f"
},
{
"status": "Running",
"name": "dp-91b905d33f",
"cpu_usage_pct": 2.1
}
]
}
],
"error": ""
}`
var exampleJson = []string{exampleJson1, exampleJson2}
file: main_test.go
package main
import (
"fmt"
"sync"
"testing"
)
//
//
// model definition for pod information
type podInfoResp struct {
Data *[]inputPodInfo `json:"data"`
Code *int `json:"code"`
Message *string `json:"message"`
Error *string `json:"error"`
}
type inputPodInfo struct {
PSM *string `json:"psm"`
NodeName *string `json:"name"`
NodeIP *string `json:"node_ip"`
ContainersInfo []containersInfo `json:"containers"`
}
type containersInfo struct {
Name *string `json:"name"`
Status *string `json:"status"`
CPUUsagePct *float64 `json:"cpu_usage_pct"`
MemUsagePct *float64 `json:"mem_usage_pct"`
}
func TestExtracJson(t *testing.T) {
wg := sync.WaitGroup{}
resultChan := make(chan podInfoResp, 2)
wg.Add(1)
go func() {
defer wg.Done()
var model podInfoResp
ExtractJson(0, &model)
resultChan <- model
}()
wg.Add(1)
go func() {
defer wg.Done()
var model podInfoResp
ExtractJson(1, &model)
resultChan <- model
}()
var results []podInfoResp
for i := 0; i < 2; i++ {
results = append(results, <-resultChan)
}
close(resultChan)
fmt.Println(*(*results[0].Data)[0].PSM)
fmt.Println(*(*results[1].Data)[0].PSM)
}
from sonic.
Fixed in #49.
from sonic.
This might be a bug within the RCU map implementation. We will investigate it later.
from sonic.
@bigfoot31 Would you please give a detail UT on this issue? Although we've been aware of where the problem is but can't reproduce the same result using old codes
from sonic.
Related Issues (20)
- Go1.16 Encode/Marshal maybe OOM when high QPS for sonic v1.10.0~v1.11.6
- Go is going to lock down future uses of `linkname` HOT 8
- optimize stream decoder SkipOneFast
- 在启用cgo环境中的情况下,编译出错ast\decode.go:31:29: cannot use 4294977024 (untyped int constant) as int value in constant declaration (overflows) HOT 3
- Error: relocation target github.com/bytedance/sonic/internal/rt.StartProf not defined HOT 4
- Checking if a field has a certain JSON type HOT 1
- Unconsumed '}' in (*traverser).decodeObject() causes entries loss after nested empty object
- make strict and accurate build tags for all source files
- support marshal NaN and INF with customed handler
- Enhance the unittest and integration testing
- minimize the performance gap for stream APIs
- make fuzz testing run longer
- Incompatible with Go 1.23, which doesn't allow //go:linkname to internal symbols, including to runtime package HOT 3
- A running error occurred in the arm environment HOT 1
- 能否添加一个MarshalIndent在根方法那里? HOT 1
- Unmarshal/Marshal for unsupported field not as encoding/json HOT 1
- What is the maximum depth of data that sonic.Marshal can serialize? HOT 1
- [BUG] unexpected quote when handling `json.Marshaler` and `,string` tag meantime HOT 1
- Why print the JSON content when call `Unmarshal` HOT 1
- [BUG] can't skip mismached-type value when it is a `,string`-tagged field
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonic.