Skip to content

Commit 8cd4f8c

Browse files
committed
fix getCnameExcludeList bug in the multithread.
1 parent 9d42018 commit 8cd4f8c

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/main/java/com/aliyun/oss/ClientConfiguration.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public class ClientConfiguration {
9999

100100
protected SignVersion signatureVersion = DEFAULT_SIGNATURE_VERSION;
101101

102+
public ClientConfiguration() {
103+
super();
104+
AppendDefaultExcludeList(this.cnameExcludeList);
105+
}
106+
102107
/**
103108
* Gets the user agent string.
104109
*
@@ -420,13 +425,6 @@ public void setProtocol(Protocol protocol) {
420425
* @return The excluded CName list, immutable.
421426
*/
422427
public List<String> getCnameExcludeList() {
423-
if (this.cnameExcludeList.size() == 0) {
424-
rlock.lock();
425-
if (this.cnameExcludeList.size() == 0) {
426-
AppendDefaultExcludeList(this.cnameExcludeList);
427-
}
428-
rlock.unlock();
429-
}
430428
return Collections.unmodifiableList(this.cnameExcludeList);
431429
}
432430

src/test/java/com/aliyun/oss/common/comm/OSSClientTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ public void testClientConfiguration() {
166166
conf.setSignerHandlers(null);
167167

168168
List<String> cnameList = conf.getCnameExcludeList();
169-
conf.setCnameExcludeList(cnameList);
169+
assertEquals(3, cnameList.size());
170+
assertEquals(true, cnameList.contains("aliyuncs.com"));
171+
assertEquals(true, cnameList.contains("aliyun-inc.com"));
172+
assertEquals(true, cnameList.contains("aliyun.com"));
173+
170174
cnameList = new ArrayList<String>();
171175
cnameList.add("");
172176
cnameList.add("cname");
@@ -177,6 +181,15 @@ public void testClientConfiguration() {
177181
assertEquals(5, gCnameList.size());
178182
assertEquals(true, gCnameList.contains("cname"));
179183
assertEquals(true, gCnameList.contains("cname1"));
184+
assertEquals(true, gCnameList.contains("aliyun-inc.com"));
185+
186+
cnameList = new ArrayList<String>();
187+
conf.setCnameExcludeList(cnameList);
188+
gCnameList = conf.getCnameExcludeList();
189+
assertEquals(3, gCnameList.size());
190+
assertEquals(true, gCnameList.contains("aliyuncs.com"));
191+
assertEquals(true, gCnameList.contains("aliyun-inc.com"));
192+
assertEquals(true, gCnameList.contains("aliyun.com"));
180193

181194
try {
182195
conf.setCnameExcludeList(null);

src/test/java/com/aliyun/oss/integrationtests/RtmpTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ public void testGeneratePushflowUri() {
622622

623623
OSS client = new OSSClientBuilder().build("https://endpoint/", "ak", "sk", "sts");
624624
uri = client.generateRtmpUri("bucket", "live", "play.m3u8", 1000 );
625-
Assert.assertTrue(uri.startsWith("rtmp://" + bucketName));
625+
Assert.assertTrue(uri.startsWith("rtmp://bucket"));
626626

627627
} catch (Exception e) {
628628
Assert.fail(e.getMessage());

0 commit comments

Comments
 (0)