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/#325 incomplete debug message #417

Merged
merged 3 commits into from
Aug 14, 2023
Merged

Conversation

mpass99
Copy link
Contributor

@mpass99 mpass99 commented Aug 1, 2023

Closes #325

In order to fix the incomplete debug message we aim to ignore output of the runner after we have sent the SIGQUIT.

We could do so by:

  • moving the SentryDebugWriter away from the debug command creation (in nomad.go) to the event processing (in nomad_runner.go).
  • Let the SentryDebugWriter probe if it can write to the CodeOceanWriter before it processes the data.
  • Passing a second context from nomad.go to the nomad_runner.go that is done when no output should be transferred (before the execution should be aborted).

I liked the second option the most which is now implemented in this PR.
The regression test is in a separate commit as it took more changes than the actual fix.

@mpass99 mpass99 self-assigned this Aug 1, 2023
@mpass99 mpass99 force-pushed the fix/#325-incomplete-debug-message branch 2 times, most recently from c27b4c4 to 35bc115 Compare August 1, 2023 12:04
@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Merging #417 (dd5117f) into main (0078b4c) will increase coverage by 0.11%.
The diff coverage is 94.33%.

@@            Coverage Diff             @@
##             main     #417      +/-   ##
==========================================
+ Coverage   75.59%   75.71%   +0.11%     
==========================================
  Files          37       37              
  Lines        3487     3508      +21     
==========================================
+ Hits         2636     2656      +20     
  Misses        686      686              
- Partials      165      166       +1     
Files Changed Coverage Δ
internal/config/config.go 96.66% <ø> (ø)
pkg/dto/dto.go 52.38% <ø> (ø)
internal/nomad/sentry_debug_writer.go 76.05% <50.00%> (-2.41%) ⬇️
cmd/poseidon/main.go 62.50% <100.00%> (ø)
internal/api/websocket.go 94.36% <100.00%> (+0.08%) ⬆️
internal/api/ws/codeocean_writer.go 79.34% <100.00%> (+4.64%) ⬆️
pkg/logging/logging.go 80.00% <100.00%> (+2.00%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mpass99 mpass99 force-pushed the fix/#325-incomplete-debug-message branch from 35bc115 to d2fcb16 Compare August 1, 2023 12:25
@mpass99 mpass99 requested a review from MrSerth August 1, 2023 13:01
@MrSerth
Copy link
Member

MrSerth commented Aug 1, 2023

Awesome, this PR (and the knowledge gained to create it) is great news! Many thanks as well to separate the regression test in a dedicated commit and writing it first (that's real TDD)!

Your code changes look fine, and I recognize the probing you suggest here. There is just a minor thing I wasn't sure about: When & how is determined that the CodeOceanWriter isn't writable any longer? Is it through this context, that gets changed in this PR?

From my (limited) understanding, the second, or third option sound good, and I am fine to go with the second one you implemented. 👍

@mpass99 mpass99 force-pushed the fix/#325-incomplete-debug-message branch from dd5117f to 50d0ea7 Compare August 13, 2023 11:54
that is created by sending SIGQUIT to the bash process
by not processing output after the the client disconnected / we have sent the SIGQUIT.
@mpass99 mpass99 force-pushed the fix/#325-incomplete-debug-message branch from 50d0ea7 to 8490e34 Compare August 13, 2023 11:54
@mpass99
Copy link
Contributor Author

mpass99 commented Aug 13, 2023

When & how is determined that the CodeOceanWriter isn't writable any longer? Is it through this context, that gets changed in this PR?

Exactly, this context represents if the CodeOceanWriter is writable or not.

  • When the client disconnects, the context is canceled here:
    connection.SetCloseHandler(func(code int, text string) error {
    log.WithContext(wsCtx).WithField("code", code).WithField("text", text).Debug("The client closed the connection.")
    cancelWsCommunication()
    • Additionally, we cleanly stop the goroutine here:
      case <-wp.ctx.Done():
      log.WithContext(wp.ctx).Info("Client closed the connection")
      wp.Input.Stop()
      wp.Output.Close(nil)
  • When an (external) error appears when sending WebSocket messages, the context is cancelled (indirectly) here as done will be true:
    done := sendMessage(cw.connection, message.data, cw.ctx)
    if done || message.done {
    writingLoopDone()
  • When the execution is done (the normal case), we Close the CodeOceanWriter here:
    case exitInfo = <-exit:
    log.WithContext(wp.ctx).Info("Execution returned")
    wp.Input.Stop()
    wp.Output.Close(&exitInfo)
    • This leads to the context being cancelled (indirectly) here as message.done will be true:
      done := sendMessage(cw.connection, message.data, cw.ctx)
      if done || message.done {
      writingLoopDone()

Copy link
Member

@MrSerth MrSerth left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for your detailed explanation. This makes sense to me, and I was now able to fully understand it :)

@MrSerth MrSerth merged commit 90092c4 into main Aug 14, 2023
12 checks passed
@MrSerth MrSerth deleted the fix/#325-incomplete-debug-message branch August 14, 2023 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exec debug message could not be read completely
2 participants