Skip to content

Commit

Permalink
bridgev2/portal: using blocking portal queue push if buffer disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jan 6, 2025
1 parent 012c246 commit 63d1d75
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions bridgev2/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Portal struct {
events chan portalEvent
}

const PortalEventBuffer = 64
var PortalEventBuffer = 64

func (br *Bridge) loadPortal(ctx context.Context, dbPortal *database.Portal, queryErr error, key *networkid.PortalKey) (*Portal, error) {
if queryErr != nil {
Expand Down Expand Up @@ -272,12 +272,16 @@ func (br *Bridge) GetExistingPortalByKey(ctx context.Context, key networkid.Port
}

func (portal *Portal) queueEvent(ctx context.Context, evt portalEvent) {
select {
case portal.events <- evt:
default:
zerolog.Ctx(ctx).Error().
Str("portal_id", string(portal.ID)).
Msg("Portal event channel is full")
if PortalEventBuffer == 0 {
portal.events <- evt
} else {
select {
case portal.events <- evt:
default:
zerolog.Ctx(ctx).Error().
Str("portal_id", string(portal.ID)).
Msg("Portal event channel is full")
}
}
}

Expand Down

0 comments on commit 63d1d75

Please sign in to comment.