Skip to content

Commit 613277c

Browse files
authored
Merge pull request #74 from DCSO/fixes
Address reconnects and protocol stability in backend communication
2 parents f977ff2 + 1c44a23 commit 613277c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

db/db_remote.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// balboa
2-
// Copyright (c) 2019, DCSO GmbH
2+
// Copyright (c) 2019, 2025, DCSO GmbH
33

44
package db
55

66
import (
7-
"gopkg.in/yaml.v2"
87
"net"
98

109
obs "github.com/DCSO/balboa/observation"
1110

1211
log "github.com/sirupsen/logrus"
12+
"gopkg.in/yaml.v2"
1313
)
1414

1515
type Backend struct {
@@ -109,8 +109,22 @@ func (db *RemoteBackend) ConsumeFeed(inChan chan obs.InputObservation) {
109109
wanted := w.Len()
110110
n, err := w.WriteTo(*conn)
111111
if err != nil {
112-
log.Warnf("sending observation failed: %s", err)
113-
continue
112+
log.Warnf("sending observation failed: %s, reconnecting", err)
113+
(*conn).Close()
114+
// try to reconnect
115+
newConn, err := net.Dial("tcp", (*conn).RemoteAddr().String())
116+
if err != nil {
117+
log.Warnf("reconnecting to backend failed: %s", err)
118+
continue
119+
}
120+
*conn = newConn
121+
// and try again
122+
n, err = w.WriteTo(*conn)
123+
if err != nil {
124+
log.Warnf("retry sending observation failed: %s", err)
125+
(*conn).Close()
126+
continue
127+
}
114128
}
115129
if n != int64(wanted) {
116130
log.Warnf("short write")

observation/input_observation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type InputObservation struct {
1818
SensorID string `codec:"I"`
1919
TimestampEnd time.Time `codec:"L"`
2020
TimestampStart time.Time `codec:"F"`
21-
Tags map[string]struct{} `codec:"G,omitempty"`
22-
Selectors map[interface{}]struct{} `codec:"S,omitempty"`
21+
Tags map[string]struct{} `codec:"-,omitempty"`
22+
Selectors map[interface{}]struct{} `codec:"-,omitempty"`
2323
}
2424

2525
// InChan is the global input channel delivering InputObservations from

0 commit comments

Comments
 (0)