mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix race
This commit is contained in:
parent
82fe001c65
commit
b71811375b
19
etcd.go
19
etcd.go
@ -250,13 +250,6 @@ func dialTimeout(network, addr string) (net.Conn, error) {
|
|||||||
return net.DialTimeout(network, addr, HTTPTimeout)
|
return net.DialTimeout(network, addr, HTTPTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Etcd struct {
|
|
||||||
http.Server
|
|
||||||
url string
|
|
||||||
scheme string
|
|
||||||
tls TLSConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start to listen and response client command
|
// Start to listen and response client command
|
||||||
func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
|
func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
|
||||||
u, err := url.Parse(info.EtcdURL)
|
u, err := url.Parse(info.EtcdURL)
|
||||||
@ -265,13 +258,11 @@ func startEtcdTransport(info Info, scheme string, tlsConf tls.Config) {
|
|||||||
}
|
}
|
||||||
infof("etcd server [%s:%s]", info.Name, u)
|
infof("etcd server [%s:%s]", info.Name, u)
|
||||||
|
|
||||||
server := &Etcd{
|
server := http.Server{
|
||||||
Server: http.Server{
|
Handler: NewEtcdMuxer(),
|
||||||
Handler: NewEtcdMuxer(),
|
TLSConfig: &tlsConf,
|
||||||
TLSConfig: &tlsConf,
|
Addr: u.Host,
|
||||||
Addr: u.Host,
|
}
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if scheme == "http" {
|
if scheme == "http" {
|
||||||
fatal(server.ListenAndServe())
|
fatal(server.ListenAndServe())
|
||||||
|
@ -165,8 +165,9 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
leader := raftServer.Leader()
|
||||||
// current no leader
|
// current no leader
|
||||||
if raftServer.Leader() == "" {
|
if leader == "" {
|
||||||
(*w).WriteHeader(http.StatusInternalServerError)
|
(*w).WriteHeader(http.StatusInternalServerError)
|
||||||
(*w).Write(newJsonError(300, ""))
|
(*w).Write(newJsonError(300, ""))
|
||||||
return
|
return
|
||||||
@ -179,10 +180,10 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
|||||||
var url string
|
var url string
|
||||||
|
|
||||||
if etcd {
|
if etcd {
|
||||||
etcdAddr, _ := nameToEtcdURL(raftServer.Leader())
|
etcdAddr, _ := nameToEtcdURL(leader)
|
||||||
url = etcdAddr + path
|
url = etcdAddr + path
|
||||||
} else {
|
} else {
|
||||||
raftAddr, _ := nameToRaftURL(raftServer.Leader())
|
raftAddr, _ := nameToRaftURL(leader)
|
||||||
url = raftAddr + path
|
url = raftAddr + path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user