2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

golang Error {write tcp 127.0.0.1:12345->127.0.0.1:12346: use of closed network connection}

Posted at

Websocksを使ってる時に出るエラー並列処理で通信中のWebsocksにまた命令を書いてるからダメってこと
例はRedis

main.go
var single chan bool

func main(){
	single = make(chan bool,1)
}
func redisGet(key string) (reply interface{}, err error) {
	single <- false
	reply,err = Conn.Do("GET", key)
	<-single
	return reply,err
}

こうしてからredisGetを並列処理で呼び出しても、通信が完了するまで.Doを実行しないためこのエラーを回避できる

参考
https://ja.stackoverflow.com/questions/20719/go%E3%81%AEwebsocket%E3%81%A7%E8%B5%B7%E3%81%8D%E3%81%9Fuse-of-closed-network-connection%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?