Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/acra-keys/keys/destroy-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (p *DestroyKeySubcommand) Parse(arguments []string) error {
default:
return ErrUnknownKeyKind
}
return nil
}

// Execute this subcommand.
Expand Down
8 changes: 4 additions & 4 deletions poison/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package poison

import (
"container/list"
"os"
"os/exec"

"github.com/cossacklabs/acra/decryptor/base"
"github.com/cossacklabs/acra/logging"
log "github.com/sirupsen/logrus"
"os"
"os/exec"
)

// EmptyCallback implements Callback and log message to show that RecordProcessor works
Expand All @@ -41,8 +42,7 @@ type StopCallback struct{}
func (*StopCallback) Call() error {
log.WithField(logging.FieldKeyEventCode, logging.EventCodePoisonRecordDetectionMessage).Warningln("Detected poison record, exit")
os.Exit(1)
log.WithField(logging.FieldKeyEventCode, logging.EventCodePoisonRecordDetectionMessage).Errorln("executed code after os.Exit")
return nil
panic("executed code after os.Exit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, is that even possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little trick I learned from the golang source code that if we want to specify that we don't need to return here, but the compiler will report an error if we don't write return, we can use panic instead.

https://github.com/golang/go/blob/43456202a1e55da55666fac9d56ace7654a65b64/src/crypto/tls/handshake_test.go#L305-L306

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is good approach, but we prefer to log it, skip bad case and continue handling further requests. It is a questionable case, do we need to log and rely on existing alerts that catch unexpected log messages and react on that or leave here panic and rely on tests (which will detect issues with os package or source code updates) and infrastructure that will restart service on failure and have enough extra instances to catch requests during restart...
After revising this case, I think will be better to leave here panic and catch it in our tests.
@Zhaars , @G1gg1L3s, what do you think?

}

// ExecuteScriptCallback represents what script to call on detecting poison record
Expand Down
6 changes: 3 additions & 3 deletions sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"

"github.com/cossacklabs/acra/sqlparser/dependency/querypb"
"github.com/cossacklabs/acra/sqlparser/dependency/sqltypes"
"github.com/cossacklabs/acra/sqlparser/dialect"
"github.com/cossacklabs/acra/sqlparser/dialect/mysql"
"github.com/cossacklabs/acra/sqlparser/dialect/postgresql"
"strconv"
"strings"
)

//go:generate goyacc -o sql.go sql.y
Expand Down Expand Up @@ -794,7 +795,6 @@ func NewPreparedQueryFromString(query string) (PreparedQuery, error) {
default:
return nil, nil
}
return nil, nil
}

// UsingInExecuteList is a set of case sensitive SQL identifiers
Expand Down
9 changes: 3 additions & 6 deletions sqlparser/parse_next_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package sqlparser

import (
"bytes"
"github.com/cossacklabs/acra/sqlparser/dialect"
"github.com/cossacklabs/acra/sqlparser/dialect/mysql"
"io"
"strings"
"testing"

"github.com/cossacklabs/acra/sqlparser/dialect"
"github.com/cossacklabs/acra/sqlparser/dialect/mysql"
)

// TestParseNextValid concatenates all the valid SQL test cases and check it can read
Expand Down Expand Up @@ -51,7 +52,6 @@ func TestParseNextValid(t *testing.T) {
tree, err := ParseNext(tokenizer)
if err != nil {
t.Fatalf("[%d] ParseNext(%q) err: %q, want nil", i, input, err)
continue
}

if got := String(tree); got != want {
Expand Down Expand Up @@ -87,14 +87,12 @@ func TestParseNextErrors(t *testing.T) {
_, err := ParseNext(tokens)
if err == nil || err.Error() != tcase.output {
t.Fatalf("[0] ParseNext(%q) err: %q, want %q", sql, err, tcase.output)
continue
}

// The second should be valid
tree, err := ParseNext(tokens)
if err != nil {
t.Fatalf("[1] ParseNext(%q) err: %q, want nil", sql, err)
continue
}

want := "select 1 from t"
Expand Down Expand Up @@ -156,7 +154,6 @@ func TestParseNextEdgeCases(t *testing.T) {
tree, err := ParseNext(tokens)
if err != nil {
t.Fatalf("[%d] ParseNext(%q) err = %q, want nil", i, test.input, err)
continue
}

if got := String(tree); got != want {
Expand Down