Skip to content

Commit c578b41

Browse files
authored
Merge pull request #528 from iExecBlockchainComputing/hotfix/8.1.1
Hotfix/8.1.1
2 parents e87fb77 + bd1fcb1 commit c578b41

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [[8.1.1]](https://github.com/iExecBlockchainComputing/iexec-worker/releases/tag/v8.1.1) 2023-06-15
6+
7+
### Bug Fixes
8+
- Do not throw exceptions from `LasService#start` method. (#528)
9+
- Add `synchronized` keyword on `LasService#start` method to avoid race conditions. (#528)
10+
511
## [[8.1.0]](https://github.com/iExecBlockchainComputing/iexec-worker/releases/tag/v8.1.0) 2023-06-12
612

713
### New Features

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=8.1.0
1+
version=8.1.1
22
iexecCommonVersion=8.2.0
33
iexecCommonsContainersVersion=1.0.2
44
iexecCommonsPocoVersion=3.0.2

src/main/java/com/iexec/worker/tee/scone/LasService.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LasService(String containerName,
3838
this.dockerService = dockerService;
3939
}
4040

41-
boolean start() {
41+
synchronized boolean start() {
4242
if (isStarted) {
4343
return true;
4444
}
@@ -53,9 +53,9 @@ boolean start() {
5353
.maxExecutionTime(0)
5454
.build();
5555
if (!imageUri.contains(sconeConfig.getRegistryName())) {
56-
// FIXME: throw an IllegalArgumentException
57-
throw new RuntimeException(String.format("LAS image (%s) is not " +
58-
"from a known registry (%s)", imageUri, sconeConfig.getRegistryName()));
56+
log.error("LAS image ({}) is not from a known registry ({})",
57+
imageUri, sconeConfig.getRegistryName());
58+
return false;
5959
}
6060
DockerClientInstance client;
6161
try {
@@ -64,9 +64,8 @@ boolean start() {
6464
sconeConfig.getRegistryUsername(),
6565
sconeConfig.getRegistryPassword());
6666
} catch (Exception e) {
67-
log.error("", e);
68-
// FIXME: throw another, more specific, Exception
69-
throw new RuntimeException("Failed to get Docker authenticated client to run LAS");
67+
log.error("Failed to get Docker authenticated client to run LAS", e);
68+
return false;
7069
}
7170
if (client == null) {
7271
log.error("Docker client with credentials is required to enable TEE support");

src/main/java/com/iexec/worker/tee/scone/LasServicesManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public class LasServicesManager implements Purgeable {
3636
*/
3737
private final Map<String, LasService> lasImageUriToLasService = new HashMap<>();
3838

39-
public LasServicesManager(SconeConfiguration sconeConfiguration,
39+
public LasServicesManager(
40+
SconeConfiguration sconeConfiguration,
4041
TeeServicesPropertiesService teeServicesPropertiesService,
4142
WorkerConfigurationService workerConfigService,
4243
SgxService sgxService,

src/test/java/com/iexec/worker/tee/scone/LasServiceTests.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import org.mockito.Mock;
1717
import org.mockito.MockitoAnnotations;
1818

19-
import static org.junit.jupiter.api.Assertions.*;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2021
import static org.mockito.ArgumentMatchers.any;
2122
import static org.mockito.Mockito.*;
2223

@@ -71,7 +72,7 @@ void shouldStartLasService() {
7172
.thenReturn(DockerRunResponse.builder().finalStatus(DockerRunFinalStatus.SUCCESS).build());
7273
when(sgxService.getSgxDriverMode()).thenReturn(SgxDriverMode.LEGACY);
7374

74-
Assertions.assertThat(lasService.start()).isTrue();
75+
assertTrue(lasService.start());
7576
verify(dockerService).run(dockerRunRequestArgumentCaptor.capture());
7677
DockerRunRequest dockerRunRequest = dockerRunRequestArgumentCaptor.getValue();
7778
Assertions.assertThat(dockerRunRequest).isEqualTo(
@@ -85,6 +86,20 @@ void shouldStartLasService() {
8586
assertTrue(lasService.isStarted());
8687
}
8788

89+
@Test
90+
void shouldStartLasServiceOnlyOnce() throws Exception {
91+
when(dockerClientInstanceMock.pullImage(IMAGE_URI)).thenReturn(true);
92+
when(dockerService.run(any()))
93+
.thenReturn(DockerRunResponse.builder().finalStatus(DockerRunFinalStatus.SUCCESS).build());
94+
when(sgxService.getSgxDriverMode()).thenReturn(SgxDriverMode.LEGACY);
95+
96+
assertTrue(lasService.start());
97+
assertTrue(lasService.start());
98+
assertTrue(lasService.isStarted());
99+
verify(dockerService).getClient(REGISTRY_NAME, REGISTRY_USERNAME, REGISTRY_PASSWORD);
100+
verify(dockerService).run(any());
101+
}
102+
88103
@Test
89104
void shouldNotStartLasServiceSinceUnknownRegistry() {
90105
LasService lasService = new LasService(
@@ -95,12 +110,8 @@ void shouldNotStartLasServiceSinceUnknownRegistry() {
95110
sgxService,
96111
dockerService
97112
);
98-
Exception exception = assertThrows(
99-
RuntimeException.class,
100-
lasService::start
101-
);
102113

103-
Assertions.assertThat(exception.getMessage()).contains("not from a known registry");
114+
assertFalse(lasService.start());
104115
assertFalse(lasService.isStarted());
105116
}
106117

@@ -109,15 +120,24 @@ void shouldNotStartLasServiceSinceClientError() throws Exception {
109120
when(dockerService.getClient(REGISTRY_NAME, REGISTRY_USERNAME, REGISTRY_PASSWORD))
110121
.thenReturn(null);
111122

112-
Assertions.assertThat(lasService.start()).isFalse();
123+
assertFalse(lasService.start());
124+
assertFalse(lasService.isStarted());
125+
}
126+
127+
@Test
128+
void shouldNotStartLasServiceSinceClientException() throws Exception {
129+
when(dockerService.getClient(REGISTRY_NAME, REGISTRY_USERNAME, REGISTRY_PASSWORD))
130+
.thenThrow(Exception.class);
131+
132+
assertFalse(lasService.start());
113133
assertFalse(lasService.isStarted());
114134
}
115135

116136
@Test
117137
void shouldNotStartLasServiceSinceCannotPullImage() {
118138
when(dockerClientInstanceMock.pullImage(IMAGE_URI)).thenReturn(false);
119139

120-
Assertions.assertThat(lasService.start()).isFalse();
140+
assertFalse(lasService.start());
121141
assertFalse(lasService.isStarted());
122142
}
123143

@@ -127,7 +147,7 @@ void shouldNotStartLasServiceSinceCannotRunDockerContainer() {
127147
when(dockerService.run(any()))
128148
.thenReturn(DockerRunResponse.builder().finalStatus(DockerRunFinalStatus.FAILED).build());
129149

130-
Assertions.assertThat(lasService.start()).isFalse();
150+
assertFalse(lasService.start());
131151
assertFalse(lasService.isStarted());
132152
}
133153
// endregion

0 commit comments

Comments
 (0)