Skip to content

Commit b0f4e65

Browse files
committed
Set OciRegistriesService.state to Started before potentially failing code to ensure close releases resources
1 parent 457f31a commit b0f4e65

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/dsl/OciRegistriesImpl.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,22 @@ internal abstract class OciRegistriesService : BuildService<BuildServiceParamete
185185
}
186186
return
187187
}
188-
state = if (currentState.registries.isEmpty()) {
189-
State.NoRegistries
188+
if (currentState.registries.isEmpty()) {
189+
state = State.NoRegistries
190190
} else {
191-
val httpServers = mutableListOf<DisposableServer>()
192191
val loopResources = OciLoopResources.acquire()
192+
val httpClient = OciRegistryHttpClient.acquire()
193+
val httpServers = mutableListOf<DisposableServer>()
194+
state = State.Started(httpServers)
193195
val redirectServer = startRedirectServer(currentState.repositoryPort.get(), loopResources)
194196
if (redirectServer != null) {
195197
httpServers += redirectServer
196198
}
197-
val imageMetadataRegistry = OciImageMetadataRegistry(OciRegistryApi(OciRegistryHttpClient.acquire()))
199+
val imageMetadataRegistry = OciImageMetadataRegistry(OciRegistryApi(httpClient))
198200
val imageMappingData = currentState.imageMapping.getData()
199201
for (registry in currentState.registries) {
200202
httpServers += startRegistryServer(registry, loopResources, imageMetadataRegistry, imageMappingData)
201203
}
202-
State.Started(httpServers)
203204
}
204205
}
205206

0 commit comments

Comments
 (0)