Fix deadlocks in single-upstream mode

This commit is contained in:
Simon Ser 2020-03-20 10:42:17 +01:00
parent aedf66c73d
commit 7714c84669
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 6 additions and 6 deletions

View file

@ -21,7 +21,7 @@ See the man page at `soju.1.scd` for more information.
## Contributing
Send patches on the [mailing list] or on [GitHub], report bugs on the
[issue tracker].
[issue tracker]. Discuss in #soju on Freenode.
## License

View file

@ -108,6 +108,7 @@ func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
}
}()
dc.logger.Printf("new connection")
return dc
}
@ -158,7 +159,7 @@ func (dc *downstreamConn) marshalEntity(uc *upstreamConn, entity string) string
}
func (dc *downstreamConn) marshalChannel(uc *upstreamConn, name string) string {
if dc.upstream() != nil {
if dc.network != nil {
return name
}
return name + "/" + uc.network.GetName()
@ -195,7 +196,7 @@ func (dc *downstreamConn) marshalNick(uc *upstreamConn, nick string) string {
if nick == uc.nick {
return dc.nick
}
if dc.upstream() != nil {
if dc.network != nil {
return nick
}
return nick + "/" + uc.network.GetName()
@ -205,7 +206,7 @@ func (dc *downstreamConn) marshalUserPrefix(uc *upstreamConn, prefix *irc.Prefix
if prefix.Name == uc.nick {
return dc.prefix()
}
if dc.upstream() != nil {
if dc.network != nil {
return prefix
}
return &irc.Prefix{
@ -225,8 +226,6 @@ func (dc *downstreamConn) isClosed() bool {
}
func (dc *downstreamConn) readMessages(ch chan<- downstreamIncomingMessage) error {
dc.logger.Printf("new connection")
for {
msg, err := dc.irc.ReadMessage()
if err == io.EOF {
@ -664,6 +663,7 @@ func (dc *downstreamConn) register() error {
dc.registered = true
dc.username = dc.user.Username
dc.logger.Printf("registration complete for user %q", dc.username)
dc.user.lock.Lock()
firstDownstream := len(dc.user.downstreamConns) == 0