File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -165,17 +165,30 @@ func (self *etcdPlugin) WatchService(name string,
165
165
166
166
// handle messages from watch service
167
167
go func () {
168
+ restart:
168
169
for {
169
170
select {
170
171
case watchResp := <- watchCh :
171
172
log .Debugf ("Received event %#v\n Node: %#v" , watchResp , watchResp .Node )
172
173
173
174
// derive service info from key
174
175
srvKey := strings .TrimPrefix (watchResp .Node .Key , "/contiv.io/service/" )
175
- srvName := strings .Split (srvKey , "/" )[0 ]
176
- hostInfo := strings .Split (srvKey , "/" )[1 ]
177
- hostAddr := strings .Split (hostInfo , ":" )[0 ]
178
- portNum , _ := strconv .Atoi (strings .Split (hostInfo , ":" )[1 ])
176
+ parts := strings .Split (srvKey , "/" )
177
+ if len (parts ) < 2 {
178
+ log .Warnf ("Recieved event for key %q, could not parse service key" , srvKey )
179
+ goto restart
180
+ }
181
+
182
+ srvName := parts [0 ]
183
+ hostAddr := parts [1 ]
184
+
185
+ parts = strings .Split (hostAddr , ":" )
186
+ if len (parts ) != 2 {
187
+ log .Warnf ("Recieved event for key %q, could not parse hostinfo" , srvKey )
188
+ goto restart
189
+ }
190
+
191
+ portNum , _ := strconv .Atoi (parts [1 ])
179
192
180
193
// Build service info
181
194
srvInfo := ServiceInfo {
You can’t perform that action at this time.
0 commit comments