Skip to content

Commit 1d037d4

Browse files
Merge branch 'develop' into docs/partial-messages-design
2 parents 92cb5a8 + a88d1ed commit 1d037d4

11 files changed

Lines changed: 94 additions & 58 deletions

File tree

build.gradle.kts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ plugins {
1818
id("java")
1919
id("maven-publish")
2020
id("org.jetbrains.dokka").version("1.9.20")
21-
id("com.diffplug.spotless").version("6.25.0")
21+
id("com.diffplug.spotless").version("7.2.1")
2222
id("java-test-fixtures")
23-
id("io.spring.dependency-management").version("1.1.6")
23+
id("io.spring.dependency-management").version("1.1.7")
2424

2525
id("org.jetbrains.kotlin.android") version kotlinVersion apply false
2626
id("com.android.application") version "7.4.2" apply false
@@ -63,6 +63,8 @@ configure(
6363

6464
testImplementation("org.junit.jupiter:junit-jupiter")
6565
testImplementation("org.junit.jupiter:junit-jupiter-params")
66+
testImplementation("org.junit.platform:junit-platform-launcher")
67+
testRuntimeOnly("org.junit.platform:junit-platform-engine")
6668
testImplementation("io.mockk:mockk")
6769
testImplementation("org.assertj:assertj-core")
6870
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl")
@@ -84,6 +86,9 @@ configure(
8486
tasks.withType<Copy> {
8587
duplicatesStrategy = DuplicatesStrategy.INCLUDE
8688
}
89+
tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
90+
jvmTarget = "11"
91+
}
8792

8893
// Parallel build execution
8994
tasks.test {
@@ -108,8 +113,10 @@ configure(
108113
}
109114

110115
configure<SpotlessExtension> {
116+
// https://github.com/pinterest/ktlint/releases
117+
val ktlintVersion = "1.1.1"
111118
kotlin {
112-
ktlint().editorConfigOverride(
119+
ktlint(ktlintVersion).editorConfigOverride(
113120
mapOf(
114121
"ktlint_standard_no-wildcard-imports" to "disabled",
115122
"ktlint_standard_enum-entry-name-case" to "disabled",
@@ -140,7 +147,7 @@ configure(
140147
jdkVersion.set(11)
141148
reportUndocumented.set(false)
142149
externalDocumentationLink {
143-
url.set(URI.create("https://netty.io/4.1/api/").toURL())
150+
url.set(URI.create("https://netty.io/4.2/api/").toURL())
144151
}
145152
}
146153
}

gradle/wrapper/gradle-wrapper.jar

-17.4 KB
Binary file not shown.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
3+
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
55
networkTimeout=10000
6+
validateDistributionUrl=true
67
zipStoreBase=GRADLE_USER_HOME
78
zipStorePath=wrapper/dists

gradlew

Lines changed: 22 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libp2p/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("com.google.protobuf").version("0.9.4")
3-
id("me.champeau.jmh").version("0.7.2")
3+
id("me.champeau.jmh").version("0.7.3")
44
}
55

66
// https://docs.gradle.org/current/userguide/java_testing.html#ex-disable-publishing-of-test-fixtures-variants
@@ -46,8 +46,6 @@ dependencies {
4646
testFixturesImplementation("org.junit.jupiter:junit-jupiter-api")
4747

4848
jmhImplementation(project(":tools:schedulers"))
49-
jmhImplementation("org.openjdk.jmh:jmh-core")
50-
jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess")
5149
}
5250

5351
protobuf {

libp2p/src/jmh/java/io/libp2p/pubsub/gossip/GossipScoreBenchmark.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,4 @@ public void scoresDelay10000(Blackhole bh) {
107107
bh.consume(s);
108108
}
109109
}
110-
111-
/** Uncomment for debugging */
112-
// public static void main(String[] args) {
113-
// GossipScoreBenchmark benchmark = new GossipScoreBenchmark();
114-
// Blackhole blackhole = new Blackhole("Today's password is swordfish. I understand
115-
// instantiating Blackholes directly is dangerous.");
116-
// benchmark.scoresDelay0(blackhole);
117-
// }
118110
}

libp2p/src/main/kotlin/io/libp2p/etc/util/netty/mux/MuxChannel.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ class MuxChannel<TData>(
3232
initializer(this)
3333
}
3434

35+
@Suppress("SwallowedException")
3536
override fun doWrite(buf: ChannelOutboundBuffer) {
3637
while (true) {
3738
val msg = buf.current() ?: break
39+
if (localDisconnected) {
40+
// Must not throw from doWrite — exceptions escape uncaught to the Netty event loop.
41+
// Wrap buf.remove() defensively: in some Netty versions promise listeners triggered
42+
// by buf.remove() can propagate back through it.
43+
try {
44+
buf.remove(ConnectionClosedException("The stream was closed for writing locally: $id"))
45+
} catch (e: Throwable) { }
46+
continue
47+
}
3848
try {
39-
if (localDisconnected) {
40-
throw ConnectionClosedException("The stream was closed for writing locally: $id")
41-
}
4249
// the msg is released by both onChildWrite and buf.remove() so we need to retain
4350
// however it is still to be confirmed that no buf leaks happen here TODO
4451
ReferenceCountUtil.retain(msg)

libp2p/src/test/kotlin/io/libp2p/mux/MuxHandlerAbstractTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.libp2p.core.StreamHandler
66
import io.libp2p.etc.types.fromHex
77
import io.libp2p.etc.types.getX
88
import io.libp2p.etc.types.toHex
9+
import io.libp2p.etc.util.netty.mux.MuxChannel
910
import io.libp2p.etc.util.netty.mux.RemoteWriteClosed
1011
import io.libp2p.etc.util.netty.nettyInitializer
1112
import io.libp2p.mux.MuxHandlerAbstractTest.AbstractTestMuxFrame.Flag.*
@@ -442,6 +443,26 @@ abstract class MuxHandlerAbstractTest {
442443
}
443444
}
444445

446+
@Test
447+
fun `write with localDisconnected should fail promise without throwing from doWrite`() {
448+
val handler = openStreamLocal()
449+
readFrameOrThrow()
450+
451+
// Simulate the state between localDisconnected=true and deactivate() in doDisconnect(),
452+
// which is when a queued WriteTask can reach doWrite with localDisconnected=true while
453+
// the channel is still active (flush0 would take the "not-yet-connected" path otherwise).
454+
@Suppress("UNCHECKED_CAST")
455+
(handler.ctx.channel() as MuxChannel<ByteBuf>).localDisconnected = true
456+
457+
val writeFuture = handler.ctx.writeAndFlush(allocateMessage("42"))
458+
ech.runPendingTasks()
459+
460+
assertTrue(writeFuture.isDone)
461+
assertThrows(ConnectionClosedException::class.java) {
462+
writeFuture.sync()
463+
}
464+
}
465+
445466
@Test
446467
fun `should throw when writing to reset stream`() {
447468
val handler = openStreamLocal()

libp2p/src/test/kotlin/io/libp2p/pubsub/gossip/GossipRpcPartsQueueTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.libp2p.pubsub.gossip.builders.GossipParamsBuilder
88
import io.libp2p.pubsub.gossip.builders.GossipRouterBuilder
99
import org.assertj.core.api.Assertions.assertThat
1010
import org.junit.jupiter.api.Test
11+
import org.junit.jupiter.params.ParameterizedInvocationConstants
1112
import org.junit.jupiter.params.ParameterizedTest
1213
import org.junit.jupiter.params.provider.Arguments
1314
import org.junit.jupiter.params.provider.MethodSource
@@ -186,7 +187,7 @@ class GossipRpcPartsQueueTest {
186187
fun mergeParams(): Stream<Arguments> = testCases.stream()
187188
}
188189

189-
@ParameterizedTest(name = "[${ParameterizedTest.INDEX_PLACEHOLDER}] {0}")
190+
@ParameterizedTest(name = "[${ParameterizedInvocationConstants.INDEX_PLACEHOLDER}] {0}")
190191
@MethodSource("mergeParams")
191192
fun `mergeMessageParts() test various combinations`(
192193
gossipParams: GossipParams,

0 commit comments

Comments
 (0)