Skip to content

Commit 9fc139d

Browse files
committed
Ensure runtime environment values are exposed through the Go runtime InitModule context.
1 parent 6813b57 commit 9fc139d

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project are documented below.
44
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).
55

66
## [Unreleased]
7+
### Added
8+
- Ensure runtime environment values are exposed through the Go runtime InitModule context.
9+
710
### Changed
811
- Log more error information when InitModule hooks from Go runtime plugins return errors.
912

server/runtime_go.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,9 @@ func NewRuntimeProviderGo(logger, startupLogger *zap.Logger, db *sql.DB, config
17901790
matchLock: matchLock,
17911791
}
17921792

1793+
// The baseline context that will be passed to all InitModule calls.
1794+
ctx := NewRuntimeGoContext(context.Background(), env, RuntimeExecutionModeRunOnce, nil, 0, "", "", "", "", "")
1795+
17931796
modulePaths := make([]string, 0)
17941797
for _, path := range paths {
17951798
if strings.ToLower(filepath.Ext(path)) != ".so" {
@@ -1821,7 +1824,7 @@ func NewRuntimeProviderGo(logger, startupLogger *zap.Logger, db *sql.DB, config
18211824
}
18221825

18231826
// Run the initialisation.
1824-
if err = fn(context.Background(), stdLogger, db, nk, initializer); err != nil {
1827+
if err = fn(ctx, stdLogger, db, nk, initializer); err != nil {
18251828
startupLogger.Fatal("Error returned by InitModule function in Go module", zap.String("name", name), zap.Error(err))
18261829
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, errors.New("error returned by InitModule function in Go module")
18271830
}

server/runtime_go_context.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import (
2222
func NewRuntimeGoContext(ctx context.Context, env map[string]string, mode RuntimeExecutionMode, queryParams map[string][]string, sessionExpiry int64, userID, username, sessionID, clientIP, clientPort string) context.Context {
2323
ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_ENV, env)
2424
ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_MODE, mode.String())
25-
ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_QUERY_PARAMS, queryParams)
25+
26+
if queryParams != nil {
27+
ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_QUERY_PARAMS, queryParams)
28+
}
2629

2730
if userID != "" {
2831
ctx = context.WithValue(ctx, runtime.RUNTIME_CTX_USER_ID, userID)

0 commit comments

Comments
 (0)