fix: fix shell host address parsing
Previously, the shell host address is assumed to have a format:
"IP:port". However, this assumption is not right if the agent is
in the same machine as the master. It could be a loopback ip address
[::1]. Now, the address parsing is fixed to cover this case.
@@ -53,7 +53,12 @@ func (a *agent) Receive(ctx *actor.Context) error {
socket, ok := msg.Accept(ctx, aproto.MasterMessage{}, true)
check.Panic(check.True(ok, "failed to accept websocket connection"))
a.socket = socket
- a.address = strings.SplitN(msg.Ctx.Request().RemoteAddr, ":", 2)[0]
+ lastColonIndex := strings.LastIndex(msg.Ctx.Request().RemoteAddr, ":")
+ if lastColonIndex == -1 {
+ a.address = msg.Ctx.Request().RemoteAddr
+ } else {
+ a.address = msg.Ctx.Request().RemoteAddr[0:lastColonIndex]
+ }
case aproto.SignalContainer:
ctx.Ask(a.socket, ws.WriteMessage{Message: aproto.AgentMessage{SignalContainer: &msg}})
case scheduler.StartTask:
