Skip to content

Commit

Permalink
Initialize listeners via RecreateListeners function
Browse files Browse the repository at this point in the history
This commit refactors the listener template to initialize variables
when RecreateListeners is called. The reason for this is that a
listener is closed when the gRPC server goes down, so a new
instance must be created.
  • Loading branch information
hsjoberg authored and halseth committed Mar 22, 2021
1 parent a9bf4b3 commit 58e52ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const toolName = "falafel"
const version = "0.8.1"
const version = "0.9.0"

var versionString = fmt.Sprintf("%s %s", toolName, version)

Expand Down
14 changes: 12 additions & 2 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import (
"google.golang.org/grpc/test/bufconn"
)
var (
{{range $lis := .Listeners}}
// {{$lis}} is a global in-memory buffer that listeners that is
{{- range $lis := .Listeners}}
// {{$lis}} is a global in-memory buffer listeners that is
// referenced by the generated mobile APIs, such that all client calls
// will be going through it.
{{$lis}} = bufconn.Listen(100)
Expand All @@ -69,6 +69,16 @@ var (
serviceDialOptionsMtx sync.Mutex
)
// RecreateListeners will re-create the in-memory listeners that will be
// referenced by the generated mobile APIs. This has to be called if the gRPC
// server has been restarted
func RecreateListeners() {
{{- range $lis := .Listeners}}
{{$lis}} = bufconn.Listen(100)
{{- end}}
}
// setDefaultDialOption sets the global default gprc option method.
func setDefaultDialOption(f func()([]grpc.DialOption, error)) {
serviceDialOptionsMtx.Lock()
Expand Down

0 comments on commit 58e52ea

Please sign in to comment.