Skip to content

Commit

Permalink
fix(baseapp): reenable sending signals at halt-height
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 5, 2024
1 parent 3730027 commit 3e27fee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG-Agoric.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (baseapp) [#338](https://github.com/agoric-labs/cosmos-sdk/pull/338) Make sure we don't execute blocks beyond the halt height. Restored from [#305](https://github.com/agoric-labs/cosmos-sdk/pull/305) but compatible with older `SIGINT`, `SIGTERM` logic
* (baseapp) [#413](https://github.com/agoric-labs/cosmos-sdk/pull/413) Ignore events from simulated transactions

## `v0.46.16-alpha.agoric.2.1` - 2024-03-08
Expand All @@ -85,7 +86,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

## `v0.46.16-alpha.agoric.1` - 2024-02-05

* Agoric/agoric-sdk#8224 Merge [cosmos/cosmos-sdk v0.46.16](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.16)
* Agoric/agoric-sdk#8224 Merge [cosmos/cosmos-sdk v0.46.16](https://github.com/osmos/cosmos-sdk/releases/tag/v0.46.16)

### Bug Fixes

Expand All @@ -99,7 +100,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (baseapp) [#337](https://github.com/agoric-labs/cosmos-sdk/pull/337) revert #305 which causes test failures in agoric-sdk
* (baseapp) [#337](https://github.com/agoric-labs/cosmos-sdk/pull/337) revert [#305](https://github.com/agoric-labs/cosmos-sdk/pull/305) which causes test failures in agoric-sdk

## `v0.45.16-alpha.agoric.1` - 2023-09-22

Expand Down
16 changes: 16 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"sort"
"strings"
"syscall"
"time"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -325,6 +327,20 @@ func (app *BaseApp) checkHalt(height int64, time time.Time) {

if halt {
app.logger.Info("halt per configuration", "height", app.haltHeight, "time", app.haltTime)

// [AGORIC] Make a best-effort attempt to kill our process.
p, err := os.FindProcess(os.Getpid())
if err == nil {
// attempt cascading signals in case SIGINT fails (os dependent)
_ = p.Signal(syscall.SIGINT)
_ = p.Signal(syscall.SIGTERM)
// Errors in these signal calls are not meaningful to us. We tried our
// best, but we don't care (and can't tell) if or how the signal handler
// responds.
}

// Prevent the state machine from advancing to the next block, no matter how
// the signals were handled.
panic(errors.New("halt application"))
}
}
Expand Down
15 changes: 15 additions & 0 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package baseapp
import (
"encoding/json"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -247,17 +250,29 @@ func TestABCI_HaltChain(t *testing.T) {
{"halt-time", 0, 10, 1, 11, true},
}

sigs := make(chan os.Signal, 5)
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.expHalt {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
}

defer func() {
rec := recover()
signal.Stop(sigs)
var err error
if rec != nil {
err = rec.(error)
}
if !tc.expHalt {
require.NoError(t, err)
} else {
// ensure that we received the correct signals
require.Equal(t, syscall.SIGINT, <-sigs)
require.Equal(t, syscall.SIGTERM, <-sigs)
require.Equal(t, len(sigs), 0)

// Check our error message.
require.Error(t, err)
require.True(t, strings.HasPrefix(err.Error(), "halt application"))
}
Expand Down

0 comments on commit 3e27fee

Please sign in to comment.