Commit 6d8195b9 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Gracefully close Lua matches when call queue fills up.

parent 46a02756
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,7 +4,8 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).

## [Unreleased]

### Fixed
- Gracefully close Lua matches when call queue fills up.

## [3.9.0] - 2021-10-29
### Added
+3 −0
Original line number Diff line number Diff line
@@ -128,10 +128,12 @@ func NewMatchHandler(logger *zap.Logger, config Config, sessionRegistry SessionR
	state, rateInt, err := core.MatchInit(presenceList, deferMessageFn, params)
	if err != nil {
		core.Cancel()
		core.Cleanup()
		return nil, err
	}
	if state == nil {
		core.Cancel()
		core.Cleanup()
		return nil, errors.New("Match initial state must not be nil")
	}

@@ -178,6 +180,7 @@ func NewMatchHandler(logger *zap.Logger, config Config, sessionRegistry SessionR

	// Continuously run queued actions until the match stops.
	go func() {
		defer core.Cleanup()
		for {
			select {
			case <-mh.stopCh:
+1 −0
Original line number Diff line number Diff line
@@ -272,6 +272,7 @@ type RuntimeMatchCore interface {
	HandlerName() string
	CreateTime() int64
	Cancel()
	Cleanup()
}

type RuntimeEventFunctions struct {
+2 −0
Original line number Diff line number Diff line
@@ -216,6 +216,8 @@ func (r *RuntimeGoMatchCore) Cancel() {
	r.ctxCancelFn()
}

func (r *RuntimeGoMatchCore) Cleanup() {}

func (r *RuntimeGoMatchCore) BroadcastMessage(opCode int64, data []byte, presences []runtime.Presence, sender runtime.Presence, reliable bool) error {
	if r.stopped.Load() {
		return ErrMatchStopped
+2 −0
Original line number Diff line number Diff line
@@ -519,6 +519,8 @@ func (rm *RuntimeJavaScriptMatchCore) Cancel() {
	// TODO: implement cancel
}

func (rm *RuntimeJavaScriptMatchCore) Cleanup() {}

func (rm *RuntimeJavaScriptMatchCore) broadcastMessage(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
		if rm.stopped.Load() {
Loading