Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup lint warning #4309

Merged
merged 4 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 11 additions & 9 deletions common/log/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ var errDefaultPanic = fmt.Errorf("panic object is not error")
// We have to use pointer is because in golang: "recover return nil if was not called directly by a deferred function."
// And we have to set the returned error otherwise our handler will return nil as error which is incorrect
func CapturePanic(logger Logger, retError *error) {
if errPanic := recover(); errPanic != nil {
err, ok := errPanic.(error)
if !ok {
err = errDefaultPanic
}
defer func() {
if errPanic := recover(); errPanic != nil {
err, ok := errPanic.(error)
if !ok {
err = errDefaultPanic
}

st := string(debug.Stack())
st := string(debug.Stack())

logger.Error("Panic is captured", tag.SysStackTrace(st), tag.Error(err))
logger.Error("Panic is captured", tag.SysStackTrace(st), tag.Error(err))

*retError = err
}
*retError = err
}
}()
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var (
registered Client = nil
registered Client
)

// NewClient gets a gocql client based registered object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type (

func NewSession(
config ClusterConfig,
) (*session, error) {
) (Session, error) {
gocqlSession, err := initSession(config)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion common/persistence/nosql/nosqlplugin/cassandra/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (db *cdb) SelectTasks(ctx context.Context, filter *nosqlplugin.TasksFilter)

iter := query.Iter()
if iter == nil {
return nil, fmt.Errorf("GetTasks operation failed. Not able to create query iterator.")
Copy link
Contributor

@longquanzheng longquanzheng Jul 9, 2021

Choose a reason for hiding this comment

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

actually, can we change to selectTasks? Or remove getTasks

return nil, fmt.Errorf("getTasks operation failed. Not able to create query iterator")
}

var response []*nosqlplugin.TaskRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cassandra

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ type (
)

func failOnPanic(t *testing.T) {
r := recover()
if r != nil {
t.Errorf("test panicked: %v %s", r, debug.Stack())
t.FailNow()
}
defer func() {
r := recover()
if r != nil {
t.Errorf("test panicked: %v %s", r, debug.Stack())
t.FailNow()
}
}()
}

// SetupSuite implementation
Expand Down
26 changes: 14 additions & 12 deletions service/history/execution/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,23 @@ func (c *Cache) makeReleaseFunc(

status := cacheNotReleased
return func(err error) {
if atomic.CompareAndSwapInt32(&status, cacheNotReleased, cacheReleased) {
if rec := recover(); rec != nil {
context.Clear()
context.Unlock()
c.Release(key)
panic(rec)
} else {
if err != nil || forceClearContext {
// TODO see issue #668, there are certain type or errors which can bypass the clear
defer func() {
if atomic.CompareAndSwapInt32(&status, cacheNotReleased, cacheReleased) {
if rec := recover(); rec != nil {
context.Clear()
context.Unlock()
c.Release(key)
panic(rec)
} else {
if err != nil || forceClearContext {
// TODO see issue #668, there are certain type or errors which can bypass the clear
context.Clear()
}
context.Unlock()
c.Release(key)
}
context.Unlock()
c.Release(key)
}
}
}()
}
}

Expand Down