MichaelSims / git-jaspr

Git Jaspr - Just Another Stacked Pull Request tool
Apache License 2.0
0 stars 1 forks source link

`git jaspr auto-merge` with a limited refspec crashes with a `Channel is closed` error #195

Open MichaelSims opened 10 months ago

MichaelSims commented 10 months ago

Reproduce steps (not reliable, see comments):

  1. Have a stack of N commits with N-1 being mergeable
  2. Run git auto-merge origin N-1:main
  3. When it merges, notice that it seems to merge the "roll up" PR properly, but crashes before it gets a chance to close the other individual PRs

Sanitized error log:

2024-01-17 09:23:35.101 [main] TRACE s.m.g.GitJaspr - merge 80bbbb422:main
2024-01-17 09:23:35.101 [main] TRACE s.m.g.CliGitClient - fetch origin
2024-01-17 09:23:35.955 [main] TRACE s.m.g.GitClient - logRange 80bbbb422..origin/main
2024-01-17 09:23:35.997 [main] TRACE s.m.g.GitClient - getLocalCommitStack origin 80bbbb422 main
2024-01-17 09:23:36.018 [main] TRACE s.m.g.GitJaspr - getRemoteCommitStatuses
2024-01-17 09:23:36.018 [main] TRACE s.m.g.GitClient - getRemoteBranchesById
2024-01-17 09:23:36.018 [main] TRACE s.m.g.GitClient - getRemoteBranches
2024-01-17 09:23:36.111 [main] TRACE s.m.g.GitHubClient - getPullRequests [REDACTED]
2024-01-17 09:23:36.112 [main] TRACE s.m.g.GitHubClient - getPullRequestsById [Icb8b755e, Ia9117498, Ibe7c9ed1, I4af365d8]
2024-01-17 09:23:38.014 [main] DEBUG s.m.g.GitHubClient - Rate limit info GitHubRateLimitInfo(cost=15, used=60, limit=5000, remaining=4940, nodeCount=9060, resetAt=2024-01-17T10:23:18)
2024-01-17 09:23:38.015 [main] TRACE s.m.g.GitHubClient - getPullRequests 4: [REDACTED]
2024-01-17 09:23:38.015 [main] TRACE s.m.g.GitHubClient - getPullRequests
2024-01-17 09:23:38.015 [main] TRACE s.m.g.GitHubClient - getPullRequestsById
2024-01-17 09:23:39.485 [main] DEBUG s.m.g.GitHubClient - Rate limit info GitHubRateLimitInfo(cost=15, used=75, limit=5000, remaining=4925, nodeCount=9060, resetAt=2024-01-17T10:23:18)
2024-01-17 09:23:39.485 [main] TRACE s.m.g.GitHubClient - getPullRequests 31: [REDACTED]
2024-01-17 09:23:39.485 [main] TRACE s.m.g.GitJaspr - getBranchesToDeleteDuringMerge [REDACTED] main
2024-01-17 09:23:39.486 [main] TRACE s.m.g.GitJaspr - Deletion candidates [TargetRefToCommitId(targetRef=main, commitId=Icb8b755e), TargetRefToCommitId(targetRef=main, commitId=Ia9117498), TargetRefToCommitId(targetRef=main, commitId=Ibe7c9ed1), TargetRefToCommitId(targetRef=main, commitId=I4af365d8)]
2024-01-17 09:23:39.486 [main] TRACE s.m.g.GitClient - getRemoteBranches
2024-01-17 09:23:39.624 [main] TRACE s.m.g.GitJaspr - Deletion list [+:jaspr/main/I4af365d8, +:jaspr/main/I4af365d8_01, +:jaspr/main/I4af365d8_02, +:jaspr/main/I4af365d8_03, +:jaspr/main/Ia9117498, +:jaspr/main/Ia9117498_01, +:jaspr/main/Ibe7c9ed1, +:jaspr/main/Ibe7c9ed1_01, +:jaspr/main/Ibe7c9ed1_02, +:jaspr/main/Ibe7c9ed1_03, +:jaspr/main/Ibe7c9ed1_04, +:jaspr/main/Icb8b755e, +:jaspr/main/Icb8b755e_01]
2024-01-17 09:23:39.625 [main] TRACE s.m.g.GitJaspr - Rebase REDACTED onto main in prep for merge
2024-01-17 09:23:39.625 [main] TRACE s.m.g.GitHubClient - updatePullRequest REDACTED
2024-01-17 09:23:41.386 [main] TRACE s.m.g.CliGitClient - push [80bbbb4:main]
2024-01-17 09:23:41.386 [main] TRACE s.m.g.CliGitClient - Filtered refSpecs to [80bbbb4:refs/heads/main]
2024-01-17 09:23:42.827 [main] INFO  s.m.g.GitJaspr - Merged 4 refs to main
2024-01-17 09:23:42.827 [main] TRACE s.m.g.GitHubClient - closePullRequest REDACTED
2024-01-17 09:23:44.003 [main] TRACE s.m.g.GitHubClient - closePullRequest REDACTED
2024-01-17 09:23:44.157 [main] ERROR s.m.g.Cli - Channel was closed
kotlinx.coroutines.channels.ClosedReceiveChannelException: Channel was closed
    at kotlinx.coroutines.channels.Closed.getReceiveException(AbstractChannel.kt:1108)
    at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.resumeReceiveClosed(AbstractChannel.kt:913)
    at kotlinx.coroutines.channels.AbstractSendChannel.helpClose(AbstractChannel.kt:342)
    at kotlinx.coroutines.channels.AbstractSendChannel.close(AbstractChannel.kt:271)
    at kotlinx.coroutines.channels.ChannelCoroutine.close(ChannelCoroutine.kt)
    at kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(Channel.kt:93)
    at io.ktor.network.tls.TLSClientHandshake$input$1.invokeSuspend(TLSClientHandshake.kt:91)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:832)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)
MichaelSims commented 9 months ago

This bug is intermittent apparently as I have not been able to reproduce it myself. I have two theories:

  1. This is a bug in Ktor or expedia's GraphQL lib (probably unlikely)
  2. This is a manifestation of a transient network problem or GitHub hanging up the connection unexpectedly (more likely)

To mitigate the first theory, I have upgraded both Ktor and the GraphQL lib in the latest release. We'll see what that does, if anything.

If it's the second one, I need to figure out the best pattern to implement a retry. I could wrap the operation that failed, but it feels wrong to trap for the exception that occurred, since that seems like a "programmer error" exception and not an I/O exception, but maybe I am mistaken about that.

I want to see if this will happen again and compare the details if it does with this first occurrence.