Comments (10)
-
是最新的master分支吗。
-
tcpx.FirstBlockOf(conn) 这个语句中的conn,有没有同时被多个地方Read。
buf, e:= tcpx.FirstBlockOf(conn)
这里的e可能有错误,贴一下
from tcpx.
fwhezfwhez 你好
我是前天go get 的包,应该是最新的
只有一个地方读取
go Recv(conn,tasks)
buf, e:=tcpx.FirstBlockOf(conn) 这里没有错误
出错的是下面这句
bufbody,err := tcpx.BodyBytesOf(buf)
if err!=nil{
fmt.Println(err.Error())
return
}
报错信息: stream lenth should be bigger than 12
就像上面说的 这个错误信息10次会出现7-8次,2,3次能正常读取
from tcpx.
buf, e:=tcpx.FirstBlockOf(conn)
在这里打印一下buf
from tcpx.
正确时候的值 buf: [24625/27264]0xc00006ca80
错误的值 buf: [10/16]0xc000090620
from tcpx.
@pickalex 你贴的buf,我看不太懂,buf应该是长这样的 [0 0 1 122 22 23 ....] 这样的。
from tcpx.
我暂时看不出问题,不过针对你的场景,进行了重演, 你可以参考一下,看看哪里使用不当了
https://github.com/fwhezfwhez/tcpx/blob/pack%2338/issue_38/server.go
https://github.com/fwhezfwhez/tcpx/blob/pack%2338/issue_38/client.go
该分支为pack#38,如下所示,并发十万次,没有复现问题。
package main
import "github.com/fwhezfwhez/tcpx"
func main() {
srv := tcpx.NewTcpX(tcpx.JsonMarshaller{})
srv.AddHandler(5, func(c *tcpx.Context) {
type Data struct {
Table string `json:"table"`
Sql string `json:"sql"`
Count string `json:"count"`
Args []interface{} `json:"args"`
Ids []string `json:"ids"`
}
var data = Data{
Table: "tcpx",
Sql: "select * from user_info",
Count: "5",
Args: []interface{}{"1", "2"},
Ids: []string{"1", "10"},
}
c.JSON(6, data)
})
if e := srv.ListenAndServe("tcp", ":8080"); e != nil {
panic(e)
}
}
package main
import (
"encoding/json"
"fmt"
"net"
"sync"
"tcpx"
)
func main() {
conn, e := net.Dial("tcp", "localhost:8080")
if e != nil {
fmt.Println(e.Error())
return
}
go recv(conn)
buf := tcpx.PackStuff(5)
wg := sync.WaitGroup{}
var jobNum = 100000
wg.Add(jobNum)
for i := 0; i < jobNum; i++ {
go func() {
defer wg.Done()
conn.Write(buf)
}()
}
wg.Wait()
fmt.Printf("成功执行完%d个任务\n", jobNum)
}
func recv(conn net.Conn) {
for {
buf, e := tcpx.FirstBlockOf(conn)
if e != nil {
panic(e)
}
var rs map[string]interface{}
bodyBuf, e := tcpx.BodyBytesOf(buf)
if e != nil {
panic(e)
}
if e := json.Unmarshal(bodyBuf, &rs); e != nil {
panic(e)
}
fmt.Println(tcpx.Debug(rs))
}
}
from tcpx.
hello ,fwhezfwhez 我看看能不能写个重现的demo,我用了第三方库sqlbuilder 构造sql 和 args,等我下
from tcpx.
fwhezfwhez ,不好意思这几天其他事情耽误了 ,因为我的代码是关联了数据库,我尝试手动弄一个假的数据集又都是正确的结果,
上面buf 打印的结构是这样的 :[0 0 0 6 0 0 0 2 0 0]
或者你得空的时候加我QQ,我们再详细讨论下 454673018 (天明),祝生活愉快
from tcpx.
晕,上面QQ号打错了,464573018
from tcpx.
已私聊解决,客户端Conn双协程读取引起的。
from tcpx.
Related Issues (20)
- [feature-asking] Can you normalize the name of the network package read interface function? HOT 1
- picture repo HOT 3
- [feature-asking]How tcpx works in distribution system?
- /root/go/src/github.com/fwhezfwhez/tcpx/log.go:34: can't read 784 length content block from reader, but read 196 HOT 14
- 有做分布式的计划吗? HOT 2
- [Promotion]Profile usage of anchor middleware
- 心跳具体要怎么配置? HOT 6
- [Promotion] Provide url style routing way, help tcpx practice better!
- 当收到错误报文时,会产生fatal error: runtime: out of memory致命错误 HOT 1
- 需要新添加可自动检测指定时间内没发送心跳就下线 HOT 1
- 需要新增一个 可以获取客户端(非极端环境下)断开连接的userid HOT 1
- 需要新增一个 HeartBeatModeDetail 可重写的 HOT 1
- 会自动触发掉线 HOT 1
- [Promotion] Enable tls
- tcp client的例子跑一下就死了 HOT 2
- [enhancement-candidate] Graceful stop, graceFul restart practice bad
- connection pool high-availeble supporting HOT 2
- go get github.com/fwhezfwhez/tcpx go get github.com/fwhezfwhez/tcpx: no matching versions for query "upgrade"
- Specifies whether TCP can be established by proxy
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 tcpx.