Skip to content

Commit

Permalink
make timeouts configurable (#508)
Browse files Browse the repository at this point in the history
* make timeouts configurable

* Apply suggestions from code review

Co-authored-by: Niklas Baudy <niklas.baudy@vanniktech.de>

---------

Co-authored-by: Niklas Baudy <niklas.baudy@vanniktech.de>
  • Loading branch information
gabrielittner and vanniktech committed Jan 29, 2023
1 parent 4b43020 commit 95f5b4e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
14 changes: 14 additions & 0 deletions docs/central.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,17 @@ by adding an extra parameter in the DSL or setting a Gradle property
Regardless of whether it is done automatically or manually after the staging repository is released the artifacts
will be synced to Maven Central. This process takes 10-30 minutes and when it is completed
the artifacts are available for download.

## Timeouts

From time to time Sonatype tends to time out during staging operations. The default timeouts of the plugin
are long already, but can be modified if needed. The timeout for HTTP requests can be modified with
`SONATYPE_CONNECT_TIMEOUT_SECONDS` which defaults to 1 minute. After a staging repository gets closed,
Sonatype will run several validations on it and the plugin needs to wait for those to finish, before it can
release the repository. The timeout for how long it is waiting for the close operation to finish can be
modified by `SONATYPE_CLOSE_TIMEOUT_SECONDS` and defaults to 15 minutes.

```properties
SONATYPE_CONNECT_TIMEOUT_SECONDS=60
SONATYPE_CLOSE_TIMEOUT_SECONDS=900
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class Nexus(
password: String,
userAgentName: String,
userAgentVersion: String,
okhttpTimeoutSeconds: Long,
private val closeTimeoutSeconds: Long,
) {
private val service by lazy {
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(NexusOkHttpInterceptor(username, password, userAgentName, userAgentVersion))
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.connectTimeout(okhttpTimeoutSeconds, TimeUnit.SECONDS)
.readTimeout(okhttpTimeoutSeconds, TimeUnit.SECONDS)
.writeTimeout(okhttpTimeoutSeconds, TimeUnit.SECONDS)
.build()
val retrofit = Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create())
Expand Down Expand Up @@ -177,7 +179,7 @@ class Nexus(
)
var i = 0
while (true) {
if (System.currentTimeMillis() - startMillis > CLOSE_TIMEOUT_MILLIS) {
if (System.currentTimeMillis() - startMillis > TimeUnit.SECONDS.toMillis(closeTimeoutSeconds)) {
throw IOException("Timeout waiting for repository close")
}

Expand Down Expand Up @@ -281,7 +283,6 @@ class Nexus(
private const val PROGRESS_6 = "\u280F"
private const val PROGRESS_7 = "\u2819"

private const val CLOSE_TIMEOUT_MILLIS = 15 * 60 * 1000L
private const val CLOSE_WAIT_INTERVAL_MILLIS = 10_000L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ internal abstract class SonatypeRepositoryBuildService : BuildService<SonatypeRe
val repositoryUsername: Property<String>
val repositoryPassword: Property<String>
val automaticRelease: Property<Boolean>
val okhttpTimeoutSeconds: Property<Long>
val closeTimeoutSeconds: Property<Long>
}

val nexus by lazy {
Expand All @@ -35,6 +37,8 @@ internal abstract class SonatypeRepositoryBuildService : BuildService<SonatypeRe
password = parameters.repositoryPassword.get(),
userAgentName = BuildConfig.NAME,
userAgentVersion = BuildConfig.VERSION,
okhttpTimeoutSeconds = parameters.okhttpTimeoutSeconds.get(),
closeTimeoutSeconds = parameters.closeTimeoutSeconds.get(),
)
}

Expand Down Expand Up @@ -93,12 +97,20 @@ internal abstract class SonatypeRepositoryBuildService : BuildService<SonatypeRe
repositoryPassword: Provider<String>,
automaticRelease: Boolean,
): Provider<SonatypeRepositoryBuildService> {
val okhttpTimeout = project.providers.gradleProperty("SONATYPE_CONNECT_TIMEOUT_SECONDS")
.map { it.toLong() }
.orElse(60)
val closeTimeout = project.providers.gradleProperty("SONATYPE_CLOSE_TIMEOUT_SECONDS")
.map { it.toLong() }
.orElse(60 * 15)
val service = gradle.sharedServices.registerIfAbsent(NAME, SonatypeRepositoryBuildService::class.java) {
it.maxParallelUsages.set(1)
it.parameters.sonatypeHost.set(sonatypeHost)
it.parameters.repositoryUsername.set(repositoryUsername)
it.parameters.repositoryPassword.set(repositoryPassword)
it.parameters.automaticRelease.set(automaticRelease)
it.parameters.okhttpTimeoutSeconds.set(okhttpTimeout)
it.parameters.closeTimeoutSeconds.set(closeTimeout)
}
project.serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(service)
return service
Expand Down

0 comments on commit 95f5b4e

Please sign in to comment.