perf: slightly optimize config/config.go

- Exclude the struct tag is space
 - Exclude configuration file comment, which is starting with space

fix: in the case of panic unexpected happened in the method parse0 of parser/parser.go, closing of the channel is needed to prevent the program from getting stuck~
  - fine-tune the coding of parser/parser.go

Limited ability, hope to make it better~
This commit is contained in:
tianyi
2022-11-01 21:40:15 +08:00
committed by finley
parent 83f2c5fad4
commit 55fd1d399d
2 changed files with 6 additions and 12 deletions

View File

@@ -76,6 +76,7 @@ func parse0(reader io.Reader, ch chan<- *Payload) {
defer func() {
if err := recover(); err != nil {
logger.Error(err, string(debug.Stack()))
close(ch)
}
}()
@@ -88,17 +89,12 @@ func parse0(reader io.Reader, ch chan<- *Payload) {
var ioErr bool
msg, ioErr, err = readLine(bufReader, &state)
if err != nil {
ch <- &Payload{Err: err}
if ioErr { // encounter io err, stop read
ch <- &Payload{
Err: err,
}
close(ch)
return
}
// protocol err, reset read state
ch <- &Payload{
Err: err,
}
state = readState{}
continue
}
@@ -227,9 +223,8 @@ func parseMultiBulkHeader(msg []byte, state *readState) error {
state.expectedArgsCount = int(expectedLine)
state.args = make([][]byte, 0, expectedLine)
return nil
} else {
return errors.New("protocol error: " + string(msg))
}
return errors.New("protocol error: " + string(msg))
}
func parseBulkHeader(msg []byte, state *readState) error {
@@ -246,9 +241,8 @@ func parseBulkHeader(msg []byte, state *readState) error {
state.expectedArgsCount = 1
state.args = make([][]byte, 0, 1)
return nil
} else {
return errors.New("protocol error: " + string(msg))
}
return errors.New("protocol error: " + string(msg))
}
func parseSingleLineReply(msg []byte) (redis.Reply, error) {