Skip to content

Fix gateway server event data change during marshaling #7430

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

Merged
merged 2 commits into from
Dec 6, 2024
Merged
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
9 changes: 9 additions & 0 deletions config/messages.json
Original file line number Diff line number Diff line change
@@ -4832,6 +4832,15 @@
"file": "pattern.go"
}
},
"error:pkg/events:marshal_data": {
"translations": {
"en": "marshal data"
},
"description": {
"package": "pkg/events",
"file": "events.go"
}
},
"error:pkg/events:no_matching_events": {
"translations": {
"en": "no matching events for regexp `{regexp}`"
22 changes: 22 additions & 0 deletions pkg/events/events.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,9 @@ import (
"strings"
"time"

"github.com/getsentry/sentry-go"
"go.thethings.network/lorawan-stack/v3/pkg/errors"
sentryerrors "go.thethings.network/lorawan-stack/v3/pkg/errors/sentry"
"go.thethings.network/lorawan-stack/v3/pkg/goproto"
"go.thethings.network/lorawan-stack/v3/pkg/jsonpb"
"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
@@ -176,7 +178,27 @@ func New(ctx context.Context, name, description string, opts ...Option) Event {
return (&definition{name: name, description: description}).New(ctx, opts...)
}

var errMarshalData = errors.Define("marshal_data", "marshal data")

func marshalData(data any) (anyPB *anypb.Any, err error) {
// TODO: https://github.com/TheThingsIndustries/lorawan-stack-support/issues/1163.
// Remove this after the issue is fixed.
defer func() {
if p := recover(); p != nil {
if pErr, ok := p.(error); ok {
err = errMarshalData.WithCause(pErr)
} else {
err = errMarshalData.WithAttributes("panic", p)
}
event := sentryerrors.NewEvent(err)
sentry.CaptureEvent(event)
}
}()

return mustMarshalData(data)
}

func mustMarshalData(data any) (anyPB *anypb.Any, err error) {
if protoMessage, ok := data.(proto.Message); ok {
anyPB, err = anypb.New(protoMessage)
if err != nil {
4 changes: 2 additions & 2 deletions pkg/gatewayserver/gatewayserver.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.

Check warning on line 1 in pkg/gatewayserver/gatewayserver.go

GitHub Actions / Check Mergeability

pkg/gatewayserver/gatewayserver.go has a conflict when merging TheThingsIndustries/lorawan-stack:v3.33.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -1101,7 +1101,7 @@
Protocol: conn.Connection.Frontend().Protocol(),
GatewayRemoteAddress: conn.Connection.GatewayRemoteAddress(),
}
registerGatewayConnectionStats(ctx, ids, stats)
registerGatewayConnectionStats(ctx, ids, ttnpb.Clone(stats))
if gs.statsRegistry != nil {
if err := gs.statsRegistry.Set(
decoupledCtx,
@@ -1121,7 +1121,7 @@
ConnectedAt: nil,
DisconnectedAt: timestamppb.Now(),
}
registerGatewayConnectionStats(decoupledCtx, ids, stats)
registerGatewayConnectionStats(decoupledCtx, ids, ttnpb.Clone(stats))
if gs.statsRegistry == nil {
return
}
1 change: 1 addition & 0 deletions pkg/webui/locales/ja.json
Original file line number Diff line number Diff line change
@@ -2362,6 +2362,7 @@
"error:pkg/events/redis:channel_closed": "チャネルが閉じています",
"error:pkg/events/redis:unknown_encoding": "不明なエンコーディング",
"error:pkg/events:invalid_regexp": "無効な正規表現",
"error:pkg/events:marshal_data": "",
"error:pkg/events:no_matching_events": "正規表現`{regexp}`に一致するイベントがありません",
"error:pkg/events:unknown_event_name": "不明なイベント`{name}`",
"error:pkg/fetch:fetch_file": "ファイル `{filename}` を取得できません",

Unchanged files with check annotations Beta

// Copyright © 2022 The Things Network Foundation, The Things Industries B.V.

Check warning on line 1 in pkg/identityserver/notification_registry.go

GitHub Actions / Check Mergeability

pkg/identityserver/notification_registry.go has a conflict when merging TheThingsIndustries/lorawan-stack:v3.33.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.