Create a new grpc exception for each duplicate result [KVL-1099] (#10887)

* Create a new grpc exception for each duplicate result

The metadata in the exception is not thread safe, and when being converted into server headers netty.Utils.convertServerHeaders, it calls discardAll which mutates the metadata. Because this was reused for all duplicate exceptions then we got corrupted metadata.

CHANGELOG_BEGIN

CHANGELOG_END

* Do not call duplicate command exception twice
This commit is contained in:
nicu-da 2021-09-15 03:45:23 -07:00 committed by GitHub
parent a939594025
commit e4cce53957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -17,7 +17,7 @@ trait ErrorFactories {
import ErrorFactories._
lazy val DuplicateCommandException: StatusRuntimeException =
def duplicateCommandException: StatusRuntimeException =
grpcError(
Status
.newBuilder()

View File

@ -17,7 +17,7 @@ class ErrorFactoriesSpec extends AnyWordSpec with Matchers with TableDrivenPrope
"ErrorFactories" should {
"return the DuplicateCommandException" in {
val status = StatusProto.fromThrowable(DuplicateCommandException)
val status = StatusProto.fromThrowable(duplicateCommandException)
status.getCode shouldBe Code.ALREADY_EXISTS.value()
status.getMessage shouldBe "Duplicate command"
status.getDetailsList.asScala shouldBe Seq(definiteAnswers(false))

View File

@ -155,8 +155,9 @@ private[apiserver] final class ApiSubmissionService private[services] (
}
case _: CommandDeduplicationDuplicate =>
metrics.daml.commands.deduplicatedCommands.mark()
logger.debug(DuplicateCommandException.getMessage)
Future.failed(DuplicateCommandException)
val exception = duplicateCommandException
logger.debug(exception.getMessage)
Future.failed(exception)
}
private def handleSubmissionResult(result: Try[state.SubmissionResult])(implicit