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

SDK WatchGameServer logs error on shutdown #3271

Merged
merged 11 commits into from
Jul 24, 2023

Conversation

Kalaiselvi84
Copy link
Contributor

What type of PR is this?

Uncomment only one /kind <> line, press enter to put that in a new line, and remove leading whitespace from that line:

/kind breaking

/kind bug

/kind cleanup
/kind documentation
/kind feature
/kind hotfix
/kind release

What this PR does / Why we need it:
Replaced fmt statements with log statements and added a condition to prevent logging when gs.ObjectMeta.DeletionTimestamp is not equal to zero

Which issue(s) this PR fixes:

Closes #3245

Special notes for your reviewer:

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: e6fbbb4f-7855-4029-84b8-8908dffc15ec

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3271/head:pr_3271 && git checkout pr_3271
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.34.0-dev-3a80553-amd64

@aimuz
Copy link
Collaborator

aimuz commented Jul 18, 2023

@clairesc for review

sdks/go/sdk.go Outdated
// This is to wait for the reconnection, and not peg the CPU at 100%.
time.Sleep(time.Second)
continue
}

if gs.ObjectMeta.DeletionTimestamp != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

So I would handle this a bit differently. There are two problems we are trying to resolve:

  1. Not output errors here when shutting down
  2. Have a pluggable log system.

So, I would actually make the second part, part of the first - because we still want to handle io.EOF as above, but not output the log.

So I would have a pluggable log as per:
#3245 (comment)

But have a function that is called here where the log functions are, that checks if gs.ObjectMeta.DeletionTimestamp.isZero() (I think that's the right function)` and if not, then runs the pluggable log function.

Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included the Logger function to log the error message when gs.ObjectMeta.DeletionTimestamp is not zero and removed log when "err == io.EOF" and any other error occurs while watching the GameServer.

DeletionTimestamp is of type int64, so I added the following condition:
if reflect.ValueOf(gs.ObjectMeta.DeletionTimestamp).IsZero() to check if it is zero or not.
reference

@google-oss-prow google-oss-prow bot added size/S and removed size/XS labels Jul 18, 2023
sdks/go/sdk.go Outdated Show resolved Hide resolved
sdks/go/sdk.go Outdated Show resolved Hide resolved
sdks/go/sdk.go Outdated Show resolved Hide resolved
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 4569518d-cef7-4b6d-bee7-e5d769f3f415

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3271/head:pr_3271 && git checkout pr_3271
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.34.0-dev-8320f71-amd64

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 03f175d6-130d-4014-abc9-91a637d5495a

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3271/head:pr_3271 && git checkout pr_3271
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.34.0-dev-c956122-amd64

sdks/go/sdk.go Outdated
@@ -132,17 +140,22 @@ func (s *SDK) WatchGameServer(f GameServerCallback) error {
if err != nil {
return errors.Wrap(err, "could not watch gameserver")
}

log := func(gs *sdk.GameServer, msg string, err error) {
if time.Unix(gs.ObjectMeta.DeletionTimestamp, 0).IsZero() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if time.Unix(gs.ObjectMeta.DeletionTimestamp, 0).IsZero() {
if gs.ObjectMeta.DeletionTimestamp.IsZero() {

This should work 🤔 , here is an example - we do this a bunch of places.

if gs.ObjectMeta.DeletionTimestamp.IsZero() {

More examples: https://github.com/search?q=repo%3Agoogleforgames%2Fagones%20IsZero&type=code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, big slice for humble 🥧 for me. I didn't realise this was the protobuf version, not the K8s API version 🤦🏻

So, we can simplify this to:

gs.ObjectMeta.DeletionTimestamp == 0

And that will make everything happy.

Sorry about that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. You are the best, always!👍🏻

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 8ba80b50-b2e2-46d1-8cde-b1040636ed2b

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3271/head:pr_3271 && git checkout pr_3271
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.34.0-dev-647b22b-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@clairesc can you take a quick look, make sure we didn't miss anything?

@clairesc
Copy link

I wanted to say LGTM but I gave it a quick go and got this exception when the GameServer is shutdown (via Fleet autoscaling)

goroutine 23 [running]:
agones.dev/agones/sdks/go.(*SDK).WatchGameServer.func1(0xc00036f5b0?, {0x146da6b?, 0xc00008ff20?}, {0x0?, 0x0?})
        /go/src/agones/sdks/go/sdk.go:144 +0x23
agones.dev/agones/sdks/go.(*SDK).WatchGameServer.func2()
        /go/src/agones/sdks/go/sdk.go:155 +0x119
created by agones.dev/agones/sdks/go.(*SDK).WatchGameServer
        /go/src/agones/sdks/go/sdk.go:149 +0x14a
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x11e0003]

I guess gs is nil when stream.Recv returns an error? (which would makes sense)


// Logger is a pluggable function that outputs the error message to standard error.
var Logger ErrorLog = func(msg string, err error) {
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err)
if gs == nil {
return
}
fmt.Fprintf(os.Stderr, "%s: %s\n", msg, err)

Since @clairesc 's comment is very good point!

Copy link
Contributor Author

@Kalaiselvi84 Kalaiselvi84 Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I add the gs == nil check here? WDYT?

log := func(gs *sdk.GameServer, msg string, err error) {
    if gs == nil || gs.ObjectMeta.DeletionTimestamp == 0 {
        return
    }
    Logger(msg, err)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's way better.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 694a9184-fbd4-496b-ab13-9e0d1f4a84ef

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@markmandel
Copy link
Member

I think I fixed this flake. Updating.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 89a7745a-8c4a-47b8-aa7d-2c9e2985d319

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3271/head:pr_3271 && git checkout pr_3271
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.34.0-dev-9886604-amd64

@markmandel
Copy link
Member

@clairesc look good now?

@clairesc
Copy link

@clairesc look good now?

Yes LGTM

@markmandel markmandel enabled auto-merge (squash) July 21, 2023 20:06
@aimuz
Copy link
Collaborator

aimuz commented Jul 22, 2023

/lgtm

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 63e69115-e00c-4daf-9c02-1f99e580f86c

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/3271/head:pr_3271 && git checkout pr_3271
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.34.0-dev-f2b6ea9-amd64

@Kalaiselvi84
Copy link
Contributor Author

@markmandel, It looks like the PR didn't get merged automatically after the successful build. Could you kindly perform the merge for this PR?🙂

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I forgot to approve. Done!

@markmandel markmandel merged commit 2f8a583 into googleforgames:main Jul 24, 2023
2 checks passed
@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Kalaiselvi84, markmandel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Kalaiselvi84 Kalaiselvi84 deleted the issues/291643455 branch March 15, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Golang SDK WatchGameServer logs error on shutdown
5 participants