Skip to content
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

fix(spanner): use correct logger when stopping emulator #609

Merged
merged 1 commit into from
Oct 31, 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
11 changes: 7 additions & 4 deletions tools/sgcloudspanner/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,24 @@ func RunEmulator(ctx context.Context) (_ func(), err error) {
}
containerID := strings.TrimSpace(dockerRunStdout.String())
cleanup := func() {
// TODO(radhus): when bumping to Go >=1.21, we should define a context like this instead and avoid storing a logger.
// ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
logger := sg.Logger(ctx)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
sg.Logger(ctx).Println("stopping down Cloud Spanner emulator...")
logger.Println("stopping down Cloud Spanner emulator...")
cmd := sgdocker.Command(ctx, "kill", containerID)
cmd.Stdout, cmd.Stderr = nil, nil
if err := cmd.Run(); err != nil {
sg.Logger(ctx).Printf("failed to kill emulator container: %v", err)
logger.Printf("failed to kill emulator container: %v", err)
}
cmd = sgdocker.Command(ctx, "rm", "-v", containerID)
cmd.Stdout, cmd.Stderr = nil, nil
if err := cmd.Run(); err != nil {
sg.Logger(ctx).Printf("failed to remove emulator container: %v", err)
logger.Printf("failed to remove emulator container: %v", err)
}
if err := os.Unsetenv("SPANNER_EMULATOR_HOST"); err != nil {
sg.Logger(ctx).Printf("failed to unset SPANNER_EMULATOR_HOST: %v", err)
logger.Printf("failed to unset SPANNER_EMULATOR_HOST: %v", err)
}
}
emulatorHost, err := inspectPortAddress(ctx, containerID, "9010/tcp")
Expand Down