forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ledger-api-client + participant-integration-api: Increase the default…
… maximum inbound error size, and truncate errors well before that. (digital-asset#6807) * participant-integration-api: `GrpcServerOwner` -> `GrpcServer.Owner`. Mostly so I can create a test class named `GrpcServerSpec`. * ports: Move the free port search from postgresql-testing. * participant-integration-api: Test the basics of GrpcServer. This uses the HelloService to make sure the server behaves normally. * ledger-api-client: Extract out channel configuration from LedgerClient. So we can test it independently of the LedgerClient itself. * ledger-api-client: Increase the default maximum inbound header size. Increased from 8 KB to 1 MB. * participant-integration-api: Reduce the maximum error message size. Truncate GRPC error descriptions to 256 KB. * participant-integration-api: Use `Port.Dynamic` instead of `FreePort`. In tests. * participant-integration-api: Explicit null checks when they're shorter. Co-authored-by: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com> * ledger-api-client: Reduce the max inbound message size back to 8 KB. And reduce the maximum size of an error description pushed out by the server accordingly. CHANGELOG_BEGIN - [Integration Kit] Truncate GPRC error messages at 4 KB. This ensures that we won't trigger a protocol error when sending errors to the client. CHANGELOG_END Co-authored-by: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>
- Loading branch information
1 parent
ee74551
commit d6fc2bb
Showing
15 changed files
with
317 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ledger/ledger-api-client/src/main/scala/com/digitalasset/ledger/client/GrpcChannel.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.client | ||
|
||
import java.net.{InetAddress, InetSocketAddress} | ||
|
||
import com.daml.ledger.client.configuration.LedgerClientConfiguration | ||
import com.daml.ports.Port | ||
import com.daml.resources.{Resource, ResourceOwner} | ||
import io.grpc.ManagedChannel | ||
import io.grpc.netty.{NegotiationType, NettyChannelBuilder} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
object GrpcChannel { | ||
|
||
final class Owner(builder: NettyChannelBuilder, configuration: LedgerClientConfiguration) | ||
extends ResourceOwner[ManagedChannel] { | ||
def this(port: Port, configuration: LedgerClientConfiguration) = | ||
this( | ||
NettyChannelBuilder | ||
.forAddress(new InetSocketAddress(InetAddress.getLoopbackAddress, port.value)), | ||
configuration, | ||
) | ||
|
||
override def acquire()(implicit executionContext: ExecutionContext): Resource[ManagedChannel] = | ||
Resource( | ||
Future { | ||
configuration.sslContext | ||
.fold(builder.usePlaintext())( | ||
builder.sslContext(_).negotiationType(NegotiationType.TLS)) | ||
builder.maxInboundMetadataSize(configuration.maxInboundMessageSize) | ||
builder.build() | ||
} | ||
)(channel => | ||
Future { | ||
channel.shutdownNow() | ||
() | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...cipant-integration-api/src/main/scala/platform/apiserver/TruncatedStatusInterceptor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.apiserver | ||
|
||
import io.grpc.ForwardingServerCall.SimpleForwardingServerCall | ||
import io.grpc.{Metadata, ServerCall, ServerCallHandler, ServerInterceptor, Status} | ||
|
||
class TruncatedStatusInterceptor(maximumDescriptionLength: Int) extends ServerInterceptor { | ||
override def interceptCall[ReqT, RespT]( | ||
call: ServerCall[ReqT, RespT], | ||
headers: Metadata, | ||
next: ServerCallHandler[ReqT, RespT], | ||
): ServerCall.Listener[ReqT] = | ||
next.startCall( | ||
new SimpleForwardingServerCall[ReqT, RespT](call) { | ||
override def close(status: Status, trailers: Metadata): Unit = { | ||
val truncatedStatus = status.withDescription(truncate(status.getDescription)) | ||
super.close(truncatedStatus, trailers) | ||
} | ||
}, | ||
headers, | ||
) | ||
|
||
private def truncate(description: String): String = | ||
if (description != null && description.length > maximumDescriptionLength) | ||
description.substring(0, maximumDescriptionLength - 3) + "..." | ||
else | ||
description | ||
} |
Oops, something went wrong.