From 17d13c335cd76ebacf8d26161fda31c83f7c04b9 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sun, 10 Jul 2022 23:24:36 +0200 Subject: [PATCH 01/18] chore(release): prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e6ff6051..9a36604e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.socket socket.io-client - 2.1.0 + 2.1.1-SNAPSHOT jar socket.io-client Socket.IO Client Library for Java @@ -30,7 +30,7 @@ https://github.com/socketio/socket.io-client-java scm:git:https://github.com/socketio/socket.io-client-java.git scm:git:https://github.com/socketio/socket.io-client-java.git - socket.io-client-2.1.0 + HEAD From 22518c9fa9b2db889b9362e64c4503a52c5b4160 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Mon, 11 Jul 2022 00:37:40 +0200 Subject: [PATCH 02/18] docs: add changelog for version 1.0.2 --- History.md | 15 +++++++++++++++ src/site/markdown/changelog.md | 14 ++++++++++++++ src/site/markdown/installation.md | 1 + 3 files changed, 30 insertions(+) diff --git a/History.md b/History.md index 18e4f07b..ea13506c 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,19 @@ +1.0.2 / 2022-07-11 +================== + +From the "1.x" branch. + +### Bug Fixes + +* ensure buffered events are sent in order ([8bd35da](https://github.com/socketio/socket.io-client-java/commit/8bd35da19c1314318fe122876d22e30ae3673ff9)) +* ensure randomizationFactor is always between 0 and 1 ([cb966d5](https://github.com/socketio/socket.io-client-java/commit/cb966d5a64790c0584ad97cf55c205cae8bd1287)) +* ensure the payload format is valid ([8664499](https://github.com/socketio/socket.io-client-java/commit/8664499b6f31154f49783531f778dac5387b766b)) +* fix usage with ws:// scheme ([e57160a](https://github.com/socketio/socket.io-client-java/commit/e57160a00ca1fbb38396effdbc87eb10d6759a51)) +* increase the readTimeout value of the default OkHttpClient ([2d87497](https://github.com/socketio/engine.io-client-java/commit/2d874971c2428a7a444b3a33afe66aedcdce3a96)) (from `engine.io-client`) + + + 2.1.0 / 2022-07-10 ================== diff --git a/src/site/markdown/changelog.md b/src/site/markdown/changelog.md index d197c228..729acdd2 100644 --- a/src/site/markdown/changelog.md +++ b/src/site/markdown/changelog.md @@ -1,4 +1,18 @@ +## [1.0.2](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-1.0.1...socket.io-client-1.0.2) (2022-07-11) + +From the "1.x" branch. + +### Bug Fixes + +* ensure buffered events are sent in order ([8bd35da](https://github.com/socketio/socket.io-client-java/commit/8bd35da19c1314318fe122876d22e30ae3673ff9)) +* ensure randomizationFactor is always between 0 and 1 ([cb966d5](https://github.com/socketio/socket.io-client-java/commit/cb966d5a64790c0584ad97cf55c205cae8bd1287)) +* ensure the payload format is valid ([8664499](https://github.com/socketio/socket.io-client-java/commit/8664499b6f31154f49783531f778dac5387b766b)) +* fix usage with ws:// scheme ([e57160a](https://github.com/socketio/socket.io-client-java/commit/e57160a00ca1fbb38396effdbc87eb10d6759a51)) +* increase the readTimeout value of the default OkHttpClient ([2d87497](https://github.com/socketio/engine.io-client-java/commit/2d874971c2428a7a444b3a33afe66aedcdce3a96)) (from `engine.io-client`) + + + ## [2.1.0](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.0.1...socket.io-client-2.1.0) (2022-07-10) diff --git a/src/site/markdown/installation.md b/src/site/markdown/installation.md index a14593a8..99318f65 100644 --- a/src/site/markdown/installation.md +++ b/src/site/markdown/installation.md @@ -39,5 +39,6 @@ implementation ('io.socket:socket.io-client:2.1.0') { | `2.1.0` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.0.1...socket.io-client-2.1.0)) | `2.1.0` ([diff](https://github.com/socketio/engine.io-client-java/compare/engine.io-client-2.0.0...engine.io-client-2.1.0)) | `3.12.12` | | `2.0.1` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.0.0...socket.io-client-2.0.1)) | `2.0.0` | `3.12.12` | | `2.0.0` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-1.0.1...socket.io-client-2.0.0)) | `2.0.0` ([diff](https://github.com/socketio/engine.io-client-java/compare/engine.io-client-1.0.1...engine.io-client-2.0.0)) | `3.12.12` | +| `1.0.2` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-1.0.1...socket.io-client-1.0.2)) | `1.0.2` ([diff](https://github.com/socketio/engine.io-client-java/compare/engine.io-client-1.0.1...engine.io-client-1.0.2)) | `3.12.12` | | `1.0.1` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-1.0.0...socket.io-client-1.0.1)) | `1.0.1` ([diff](https://github.com/socketio/engine.io-client-java/compare/engine.io-client-1.0.0...engine.io-client-1.0.1)) | `3.12.12` ([changelog](https://square.github.io/okhttp/changelogs/changelog_3x/#version-31212)) | | `1.0.0` | `1.0.0` | `3.8.1` | From ad3a930e346ad54acd8e895b01418f7b936776dd Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Mon, 11 Jul 2022 10:11:34 +0200 Subject: [PATCH 03/18] docs: how to run unit tests in Android Studio Related: https://github.com/socketio/socket.io-client-java/issues/493 --- src/site/markdown/android.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/site/markdown/android.md b/src/site/markdown/android.md index a33b2f92..be5c7906 100644 --- a/src/site/markdown/android.md +++ b/src/site/markdown/android.md @@ -57,3 +57,27 @@ Starting with Android 9 (API level 28) you need to explicitly allow cleartext tr ``` Reference: https://developer.android.com/training/articles/security-config + +## How to run unit tests in Android Studio? + +Local unit tests are tests that run on your machine's local Java Virtual Machine. + +Reference: https://developer.android.com/studio/test/test-in-android-studio + +Since they run on your machine, the JSON library must be manually included for the tests (because it is not provided by the Android runtime): + +`build.gradle` + +``` +dependencies { + implementation ('io.socket:socket.io-client:2.0.1') { + exclude group: 'org.json', module: 'json' + } + + testImplementation 'org.json:json:20090211' + + ... +} +``` + +Note: we use this ancient version of `org.json` because it is compatible with the one bundled in Android. From 774543ef57a3a6bb0e409949a0810fea8ee46192 Mon Sep 17 00:00:00 2001 From: FarmersWrap <111668967+FarmersWrap@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:52:15 -0600 Subject: [PATCH 04/18] test: silence expected error (#757) --- src/test/java/io/socket/parser/ParserTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/socket/parser/ParserTest.java b/src/test/java/io/socket/parser/ParserTest.java index 17d48863..8b239cb8 100644 --- a/src/test/java/io/socket/parser/ParserTest.java +++ b/src/test/java/io/socket/parser/ParserTest.java @@ -1,5 +1,8 @@ package io.socket.parser; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.json.JSONArray; import org.json.JSONException; import org.junit.Test; @@ -49,6 +52,9 @@ public void encodeAck() throws JSONException { @Test public void decodeInError() throws JSONException { + Logger logger = Logger.getLogger(IOParser.class.getName()); + Level tmpLevel = logger.getLevel(); + logger.setLevel(Level.SEVERE); // Random string Helpers.testDecodeError("asdf"); // Unknown type @@ -62,9 +68,10 @@ public void decodeInError() throws JSONException { // event non numeric id Helpers.testDecodeError(Parser.EVENT + "2sd"); // event with invalid json data - Helpers.testDecodeError(Parser.EVENT + "2[\"a\",1,{asdf}]"); Helpers.testDecodeError(Parser.EVENT + "2{}"); Helpers.testDecodeError(Parser.EVENT + "2[]"); Helpers.testDecodeError(Parser.EVENT + "2[null]"); + Helpers.testDecodeError(Parser.EVENT + "2[\"a\",1,{asdf}]"); + logger.setLevel(tmpLevel); } } From b00ae8eec1ef0aa5094fca7fad918a437603eb12 Mon Sep 17 00:00:00 2001 From: Harshvardhan Gupta <95761669+Harsh5488@users.noreply.github.com> Date: Wed, 10 Jul 2024 14:40:17 +0530 Subject: [PATCH 05/18] fix: make sendBuffer thread safe (#769) Clearing the buffer upon timeout could lead to: ``` java.util.ConcurrentModificationException at java.base/java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:970) at java.base/java.util.LinkedList$ListItr.next(LinkedList.java:892) at io.socket.client.Socket$6$1.run(Socket.java:232) at java.base/java.util.TimerThread.mainLoop(Timer.java:556) at java.base/java.util.TimerThread.run(Timer.java:506) ``` Related: - https://github.com/socketio/socket.io-client-java/issues/710 - https://github.com/socketio/socket.io-client-java/issues/727 - https://github.com/socketio/socket.io-client-java/pull/758 - https://github.com/socketio/socket.io-client-java/issues/759 --- src/main/java/io/socket/client/Socket.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/socket/client/Socket.java b/src/main/java/io/socket/client/Socket.java index 49bc3784..7e131d0b 100644 --- a/src/main/java/io/socket/client/Socket.java +++ b/src/main/java/io/socket/client/Socket.java @@ -61,8 +61,8 @@ public class Socket extends Emitter { private Map auth; private Map acks = new HashMap<>(); private Queue subs; - private final Queue> receiveBuffer = new LinkedList<>(); - private final Queue> sendBuffer = new LinkedList<>(); + private final Queue> receiveBuffer = new ConcurrentLinkedQueue<>(); + private final Queue> sendBuffer = new ConcurrentLinkedQueue<>(); private ConcurrentLinkedQueue onAnyIncomingListeners = new ConcurrentLinkedQueue<>(); private ConcurrentLinkedQueue onAnyOutgoingListeners = new ConcurrentLinkedQueue<>(); From 54645ece2cd132f3e305b80904e1fc38bd41c4f9 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 10 Jul 2024 11:38:53 +0200 Subject: [PATCH 06/18] fix: discard acknowledgements upon disconnection Previously, getting disconnected while waiting for an acknowledgement would create a memory leak, as the acknowledgement was never received and the handler would stay in memory forever. See also: https://github.com/socketio/socket.io-client/commit/34cbfbb532ae333f4dd034138e8f87cb80a8e382 Related: https://github.com/socketio/socket.io-client-java/issues/446 --- src/main/java/io/socket/client/Socket.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/socket/client/Socket.java b/src/main/java/io/socket/client/Socket.java index 7e131d0b..334d25f5 100644 --- a/src/main/java/io/socket/client/Socket.java +++ b/src/main/java/io/socket/client/Socket.java @@ -283,6 +283,21 @@ private void onclose(String reason) { this.connected = false; this.id = null; super.emit(EVENT_DISCONNECT, reason); + this.clearAcks(); + } + + /** + * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from + * the server. + */ + private void clearAcks() { + for (Ack ack : this.acks.values()) { + if (ack instanceof AckWithTimeout) { + ((AckWithTimeout) ack).onTimeout(); + } + // note: basic Ack objects have no way to report an error, so they are simply ignored here + } + this.acks.clear(); } private void onpacket(Packet packet) { @@ -448,12 +463,6 @@ private void destroy() { this.subs = null; } - for (Ack ack : acks.values()) { - if (ack instanceof AckWithTimeout) { - ((AckWithTimeout) ack).cancelTimer(); - } - } - this.io.destroy(); } From 0e11f2f7bb17feff2f883fd1652fd639001e4ef3 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 10 Jul 2024 11:57:59 +0200 Subject: [PATCH 07/18] chore(release): prepare release socket.io-client-2.1.1 --- History.md | 10 ++++++++++ pom.xml | 6 +++--- src/site/markdown/changelog.md | 23 +++++++++++++++++++++++ src/site/markdown/installation.md | 5 +++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index ea13506c..463d09bf 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,14 @@ +2.1.1 / 2024-07-10 +================== + +### Bug Fixes + +* discard acknowledgements upon disconnection ([54645ec](https://github.com/socketio/socket.io-client-java/commit/54645ece2cd132f3e305b80904e1fc38bd41c4f9)) +* make sendBuffer thread safe ([#769](https://github.com/socketio/socket.io-client-java/issues/769)) ([b00ae8e](https://github.com/socketio/socket.io-client-java/commit/b00ae8eec1ef0aa5094fca7fad918a437603eb12)) + + + 1.0.2 / 2022-07-11 ================== diff --git a/pom.xml b/pom.xml index 9a36604e..59c4fc32 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.socket socket.io-client - 2.1.1-SNAPSHOT + 2.1.1 jar socket.io-client Socket.IO Client Library for Java @@ -30,7 +30,7 @@ https://github.com/socketio/socket.io-client-java scm:git:https://github.com/socketio/socket.io-client-java.git scm:git:https://github.com/socketio/socket.io-client-java.git - HEAD + socket.io-client-2.1.1 @@ -184,7 +184,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 + 1.6.13 true ossrh diff --git a/src/site/markdown/changelog.md b/src/site/markdown/changelog.md index 729acdd2..1939253f 100644 --- a/src/site/markdown/changelog.md +++ b/src/site/markdown/changelog.md @@ -1,3 +1,26 @@ +# History + +| Version | Release date | +|--------------------------------------------------------------------------------------------------------------|---------------| +| [2.1.1](#211-2024-07-10) | July 2024 | +| [1.0.2](#102-2022-07-11) (from the [1.x](https://github.com/socketio/socket.io-client-java/tree/1.x) branch) | July 2022 | +| [2.1.0](#210-2022-07-10) | July 2022 | +| [2.0.1](#201-2021-04-27) | April 2021 | +| [2.0.0](#200-2020-12-14) | December 2020 | +| [1.0.1](#101-2020-12-10) | December 2020 | + + +# Release notes + +## [2.1.1](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.1.0...socket.io-client-2.1.1) (2024-07-10) + + +### Bug Fixes + +* discard acknowledgements upon disconnection ([54645ec](https://github.com/socketio/socket.io-client-java/commit/54645ece2cd132f3e305b80904e1fc38bd41c4f9)) +* make sendBuffer thread safe ([#769](https://github.com/socketio/socket.io-client-java/issues/769)) ([b00ae8e](https://github.com/socketio/socket.io-client-java/commit/b00ae8eec1ef0aa5094fca7fad918a437603eb12)) + + ## [1.0.2](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-1.0.1...socket.io-client-1.0.2) (2022-07-11) diff --git a/src/site/markdown/installation.md b/src/site/markdown/installation.md index 99318f65..de61a1e7 100644 --- a/src/site/markdown/installation.md +++ b/src/site/markdown/installation.md @@ -17,7 +17,7 @@ Add the following dependency to your `pom.xml`. io.socket socket.io-client - 2.1.0 + 2.1.1 ``` @@ -26,7 +26,7 @@ Add the following dependency to your `pom.xml`. Add it as a gradle dependency for Android Studio, in `build.gradle`: ```groovy -implementation ('io.socket:socket.io-client:2.1.0') { +implementation ('io.socket:socket.io-client:2.1.1') { // excluding org.json which is provided by Android exclude group: 'org.json', module: 'json' } @@ -36,6 +36,7 @@ implementation ('io.socket:socket.io-client:2.1.0') { | `socket.io-client` | `engine.io-client` | `okhttp` | |-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------| +| `2.1.1` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.1.0...socket.io-client-2.1.1)) | `2.1.0` | `3.12.12` | | `2.1.0` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.0.1...socket.io-client-2.1.0)) | `2.1.0` ([diff](https://github.com/socketio/engine.io-client-java/compare/engine.io-client-2.0.0...engine.io-client-2.1.0)) | `3.12.12` | | `2.0.1` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.0.0...socket.io-client-2.0.1)) | `2.0.0` | `3.12.12` | | `2.0.0` ([diff](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-1.0.1...socket.io-client-2.0.0)) | `2.0.0` ([diff](https://github.com/socketio/engine.io-client-java/compare/engine.io-client-1.0.1...engine.io-client-2.0.0)) | `3.12.12` | From 6d5d74ed8cb1e992e5ffa0fe3582f0e10584295f Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 10 Jul 2024 12:23:32 +0200 Subject: [PATCH 08/18] chore(release): prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 59c4fc32..1ffccd11 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.socket socket.io-client - 2.1.1 + 2.1.2-SNAPSHOT jar socket.io-client Socket.IO Client Library for Java @@ -30,7 +30,7 @@ https://github.com/socketio/socket.io-client-java scm:git:https://github.com/socketio/socket.io-client-java.git scm:git:https://github.com/socketio/socket.io-client-java.git - socket.io-client-2.1.1 + HEAD From 6ea9c15a34bc2cf2aef0b85f77d949853c88231a Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 10 Jul 2024 12:27:19 +0200 Subject: [PATCH 09/18] ci: fix java 7 build In order to prevent: > Error: Exception in thread "main" java.lang.UnsupportedClassVersionError: com/fasterxml/jackson/databind/ObjectMapper : Unsupported major.minor version 52.0 > at java.lang.ClassLoader.defineClass1(Native Method) > at java.lang.ClassLoader.defineClass(ClassLoader.java:808) --- .github/workflows/ci.yml | 1 + pom.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 439755f9..422605e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: java: [7, 8, 11] diff --git a/pom.xml b/pom.xml index 1ffccd11..2e7a8021 100644 --- a/pom.xml +++ b/pom.xml @@ -184,7 +184,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.6.7 true ossrh From 4f45e3c1271554da5b3457f447a6d6b060ef5ffd Mon Sep 17 00:00:00 2001 From: Harshvardhan Gupta <95761669+Harsh5488@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:46:05 +0530 Subject: [PATCH 10/18] fix: make acks thread safe (#779) --- src/main/java/io/socket/client/Socket.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/socket/client/Socket.java b/src/main/java/io/socket/client/Socket.java index 334d25f5..bfcb2ad6 100644 --- a/src/main/java/io/socket/client/Socket.java +++ b/src/main/java/io/socket/client/Socket.java @@ -9,6 +9,7 @@ import org.json.JSONObject; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Level; import java.util.logging.Logger; @@ -59,7 +60,7 @@ public class Socket extends Emitter { private String nsp; private Manager io; private Map auth; - private Map acks = new HashMap<>(); + private Map acks = new ConcurrentHashMap<>(); private Queue subs; private final Queue> receiveBuffer = new ConcurrentLinkedQueue<>(); private final Queue> sendBuffer = new ConcurrentLinkedQueue<>(); From 54852ce2a47d79ea0ae12fd24b56beb31c3eeb3a Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 6 Feb 2025 09:26:04 +0100 Subject: [PATCH 11/18] ci: fix java 7 build Maven has been upgraded from 3.8 to 3.9, which is not compatible with JDK 7. See also: https://github.com/actions/runner-images/issues/11093 --- .github/workflows/ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 422605e7..d409d796 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,19 +17,32 @@ jobs: steps: - uses: actions/checkout@v2 + + - name: Install Maven 3.8.x (instead of 3.9.x) + run: | + MAVEN_VERSION=3.8.8 + wget https://downloads.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz + tar xzvf apache-maven-$MAVEN_VERSION-bin.tar.gz + sudo mv apache-maven-$MAVEN_VERSION /opt/maven + sudo rm -f /usr/bin/mvn # Remove existing symbolic link if it exists + sudo ln -s /opt/maven/bin/mvn /usr/bin/mvn # Create new symbolic link + - name: Setup java uses: actions/setup-java@v1 with: java-version: ${{ matrix.java }} + - name: Cache Maven packages uses: actions/cache@v2 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 + - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 14.x + - name: Run the Maven verify phase run: mvn verify -Dgpg.skip=true From e2cdf7b99c0bff9fedb4761b8860ea65f108782a Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Feb 2025 09:32:41 +0100 Subject: [PATCH 12/18] refactor: make fields final when possible --- src/main/java/io/socket/client/Manager.java | 19 ++++++++----------- src/main/java/io/socket/client/Socket.java | 16 +++++++--------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/socket/client/Manager.java b/src/main/java/io/socket/client/Manager.java index a3c5f19e..04198998 100644 --- a/src/main/java/io/socket/client/Manager.java +++ b/src/main/java/io/socket/client/Manager.java @@ -72,20 +72,20 @@ public class Manager extends Emitter { private long _reconnectionDelay; private long _reconnectionDelayMax; private double _randomizationFactor; - private Backoff backoff; + private final Backoff backoff; private long _timeout; - private URI uri; - private List packetBuffer; - private Queue subs; - private Options opts; + private final URI uri; + private final List packetBuffer = new ArrayList<>(); + private final Queue subs = new LinkedList<>();; + private final Options opts; /*package*/ io.socket.engineio.client.Socket engine; - private Parser.Encoder encoder; - private Parser.Decoder decoder; + private final Parser.Encoder encoder; + private final Parser.Decoder decoder; /** * This HashMap can be accessed from outside of EventThread. */ - /*package*/ ConcurrentHashMap nsps; + /*package*/ final Map nsps = new ConcurrentHashMap<>(); public Manager() { @@ -114,8 +114,6 @@ public Manager(URI uri, Options opts) { opts.callFactory = defaultCallFactory; } this.opts = opts; - this.nsps = new ConcurrentHashMap<>(); - this.subs = new LinkedList<>(); this.reconnection(opts.reconnection); this.reconnectionAttempts(opts.reconnectionAttempts != 0 ? opts.reconnectionAttempts : Integer.MAX_VALUE); this.reconnectionDelay(opts.reconnectionDelay != 0 ? opts.reconnectionDelay : 1000); @@ -129,7 +127,6 @@ public Manager(URI uri, Options opts) { this.readyState = ReadyState.CLOSED; this.uri = uri; this.encoding = false; - this.packetBuffer = new ArrayList<>(); this.encoder = opts.encoder != null ? opts.encoder : new IOParser.Encoder(); this.decoder = opts.decoder != null ? opts.decoder : new IOParser.Decoder(); } diff --git a/src/main/java/io/socket/client/Socket.java b/src/main/java/io/socket/client/Socket.java index bfcb2ad6..eccf09c5 100644 --- a/src/main/java/io/socket/client/Socket.java +++ b/src/main/java/io/socket/client/Socket.java @@ -57,23 +57,21 @@ public class Socket extends Emitter { private volatile boolean connected; private int ids; - private String nsp; - private Manager io; - private Map auth; - private Map acks = new ConcurrentHashMap<>(); + private final String nsp; + private final Manager io; + private final Map auth; + private final Map acks = new ConcurrentHashMap<>(); private Queue subs; private final Queue> receiveBuffer = new ConcurrentLinkedQueue<>(); private final Queue> sendBuffer = new ConcurrentLinkedQueue<>(); - private ConcurrentLinkedQueue onAnyIncomingListeners = new ConcurrentLinkedQueue<>(); - private ConcurrentLinkedQueue onAnyOutgoingListeners = new ConcurrentLinkedQueue<>(); + private final ConcurrentLinkedQueue onAnyIncomingListeners = new ConcurrentLinkedQueue<>(); + private final ConcurrentLinkedQueue onAnyOutgoingListeners = new ConcurrentLinkedQueue<>(); public Socket(Manager io, String nsp, Manager.Options opts) { this.io = io; this.nsp = nsp; - if (opts != null) { - this.auth = opts.auth; - } + this.auth = opts != null ? opts.auth : null; } private void subEvents() { From 80aa47158e57fc16471b00ea7ece5e50754e5b25 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Feb 2025 09:37:01 +0100 Subject: [PATCH 13/18] refactor: merge duplicate cases --- src/main/java/io/socket/client/Socket.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/socket/client/Socket.java b/src/main/java/io/socket/client/Socket.java index eccf09c5..2227a30d 100644 --- a/src/main/java/io/socket/client/Socket.java +++ b/src/main/java/io/socket/client/Socket.java @@ -315,13 +315,7 @@ private void onpacket(Packet packet) { break; } - case Parser.EVENT: { - @SuppressWarnings("unchecked") - Packet p = (Packet) packet; - this.onevent(p); - break; - } - + case Parser.EVENT: case Parser.BINARY_EVENT: { @SuppressWarnings("unchecked") Packet p = (Packet) packet; @@ -329,13 +323,7 @@ private void onpacket(Packet packet) { break; } - case Parser.ACK: { - @SuppressWarnings("unchecked") - Packet p = (Packet) packet; - this.onack(p); - break; - } - + case Parser.ACK: case Parser.BINARY_ACK: { @SuppressWarnings("unchecked") Packet p = (Packet) packet; From 667bd17a01b97306be7a364c409b201b0a9eb017 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Feb 2025 09:49:09 +0100 Subject: [PATCH 14/18] chore(release): prepare release socket.io-client-2.1.2 --- History.md | 9 +++++++++ pom.xml | 4 ++-- src/site/markdown/changelog.md | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 463d09bf..1366aaec 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,13 @@ +2.1.2 / 2025-02-18 +================== + +### Bug Fixes + +- make acks thread safe ([4f45e3c](https://github.com/socketio/socket.io-client-java/commit/4f45e3c1271554da5b3457f447a6d6b060ef5ffd)) + + + 2.1.1 / 2024-07-10 ================== diff --git a/pom.xml b/pom.xml index 2e7a8021..70ca5e46 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.socket socket.io-client - 2.1.2-SNAPSHOT + 2.1.2 jar socket.io-client Socket.IO Client Library for Java @@ -30,7 +30,7 @@ https://github.com/socketio/socket.io-client-java scm:git:https://github.com/socketio/socket.io-client-java.git scm:git:https://github.com/socketio/socket.io-client-java.git - HEAD + socket.io-client-2.1.2 diff --git a/src/site/markdown/changelog.md b/src/site/markdown/changelog.md index 1939253f..e671c86a 100644 --- a/src/site/markdown/changelog.md +++ b/src/site/markdown/changelog.md @@ -2,6 +2,7 @@ | Version | Release date | |--------------------------------------------------------------------------------------------------------------|---------------| +| [2.1.2](#211-2025-02-18) | February 2025 | | [2.1.1](#211-2024-07-10) | July 2024 | | [1.0.2](#102-2022-07-11) (from the [1.x](https://github.com/socketio/socket.io-client-java/tree/1.x) branch) | July 2022 | | [2.1.0](#210-2022-07-10) | July 2022 | @@ -12,6 +13,15 @@ # Release notes +## [2.1.2](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.1.1...socket.io-client-2.1.2) (2025-02-18) + + +### Bug Fixes + +* make acks thread safe ([4f45e3c](https://github.com/socketio/socket.io-client-java/commit/4f45e3c1271554da5b3457f447a6d6b060ef5ffd)) + + + ## [2.1.1](https://github.com/socketio/socket.io-client-java/compare/socket.io-client-2.1.0...socket.io-client-2.1.1) (2024-07-10) From bc4ca533df7f6445626289bc0c39dbda05a4373e Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Feb 2025 10:04:12 +0100 Subject: [PATCH 15/18] chore(release): prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 70ca5e46..f2a7dee0 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.socket socket.io-client - 2.1.2 + 2.1.3-SNAPSHOT jar socket.io-client Socket.IO Client Library for Java @@ -30,7 +30,7 @@ https://github.com/socketio/socket.io-client-java scm:git:https://github.com/socketio/socket.io-client-java.git scm:git:https://github.com/socketio/socket.io-client-java.git - socket.io-client-2.1.2 + HEAD @@ -184,7 +184,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 + 1.6.13 true ossrh From 9436451b8c23a329b05552e8d4e13985ac8e9c11 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Feb 2025 22:12:01 +0100 Subject: [PATCH 16/18] ci: fix java 7 build (bis) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f2a7dee0..4636cb1b 100644 --- a/pom.xml +++ b/pom.xml @@ -184,7 +184,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.6.7 true ossrh From 822fe23bf840009cf3b9bd545a1b66fe615cda87 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 18 Feb 2025 22:17:54 +0100 Subject: [PATCH 17/18] ci: update actions/cache to v4 Reference: https://github.blog/changelog/2024-12-05-notice-of-upcoming-releases-and-breaking-changes-for-github-actions/#actions-cache-v1-v2-and-actions-toolkit-cache-package-closing-down --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d409d796..22b0af32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,9 +33,9 @@ jobs: java-version: ${{ matrix.java }} - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: - path: ~/.m2 + path: ~/.m2/repository key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 From eb438de0f7038a075db4c7eff53fd0e7f13116ce Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Mon, 11 Aug 2025 09:25:33 +0200 Subject: [PATCH 18/18] ci: upgrade maven to version 3.8.9 Previous version is no longer available at [1]. [1]: https://dlcdn.apache.org/maven/maven-3/ --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22b0af32..8531e775 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Install Maven 3.8.x (instead of 3.9.x) run: | - MAVEN_VERSION=3.8.8 + MAVEN_VERSION=3.8.9 wget https://downloads.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz tar xzvf apache-maven-$MAVEN_VERSION-bin.tar.gz sudo mv apache-maven-$MAVEN_VERSION /opt/maven