Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] UnsupportedOperationException when building nativeHeaders #24649

Closed
moarychan opened this issue Oct 8, 2021 · 0 comments · Fixed by #24669
Closed

[BUG] UnsupportedOperationException when building nativeHeaders #24649

moarychan opened this issue Oct 8, 2021 · 0 comments · Fixed by #24669
Assignees
Labels
azure-spring All azure-spring related issues azure-spring-eventhubs Spring event hubs related issues. bug This issue requires a change to an existing behavior in the product in order to be resolved.

Comments

@moarychan
Copy link
Member

Describe the bug
The UnsupportedOperationException will be encountered when azure-spring-cloud-stream-binder-eventhubs and spring-cloud-starter-sleuth are used together.
The PR microsoft/spring-cloud-azure#743 and microsoft/spring-cloud-azure#744 were to fix the issue microsoft/spring-cloud-azure#592. At that time, the properties of the EventData could still be modified, this PR #22314 changed properties to an unmodifiable Map, then a mistake was made without sufficient testing during version upgrade.

Exception or Stack Trace

com.azure.messaging.eventhubs.implementation.PartitionProcessorException: Error in event processing callback
	at com.azure.messaging.eventhubs.PartitionPumpManager.processEvents(PartitionPumpManager.java:322) ~[azure-messaging-eventhubs-5.10.1.jar:5.10.1]
	at com.azure.messaging.eventhubs.PartitionPumpManager.lambda$startPartitionPump$2(PartitionPumpManager.java:235) ~[azure-messaging-eventhubs-5.10.1.jar:5.10.1]
	at reactor.core.publisher.LambdaSubscriber.onNext(LambdaSubscriber.java:160) ~[reactor-core-3.4.9.jar:3.4.9]
	at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.runAsync(FluxPublishOn.java:440) ~[reactor-core-3.4.9.jar:3.4.9]
	at reactor.core.publisher.FluxPublishOn$PublishOnSubscriber.run(FluxPublishOn.java:527) ~[reactor-core-3.4.9.jar:3.4.9]
	at org.springframework.cloud.sleuth.instrument.reactor.ReactorSleuth.lambda$null$6(ReactorSleuth.java:309) ~[spring-cloud-sleuth-instrumentation-3.0.3.jar:3.0.3]
	at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84) ~[reactor-core-3.4.9.jar:3.4.9]
	at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37) ~[reactor-core-3.4.9.jar:3.4.9]
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na]
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: com.azure.messaging.eventhubs.implementation.PartitionProcessorException: Error in event processing callback
	at com.azure.messaging.eventhubs.PartitionPumpManager.processEvent(PartitionPumpManager.java:284) ~[azure-messaging-eventhubs-5.10.1.jar:5.10.1]
	at com.azure.messaging.eventhubs.PartitionPumpManager.processEvents(PartitionPumpManager.java:318) ~[azure-messaging-eventhubs-5.10.1.jar:5.10.1]
	... 13 common frames omitted
Caused by: java.lang.UnsupportedOperationException: null
	at java.base/java.util.Collections$UnmodifiableMap.remove(Collections.java:1460) ~[na:na]
	at com.azure.spring.integration.eventhub.converter.EventHubMessageConverter.buildCustomHeaders(EventHubMessageConverter.java:80) ~[azure-spring-integration-eventhubs-2.9.0.jar:2.9.0]
	at com.azure.spring.integration.eventhub.converter.EventHubMessageConverter.buildCustomHeaders(EventHubMessageConverter.java:30) ~[azure-spring-integration-eventhubs-2.9.0.jar:2.9.0]
	at com.azure.spring.integration.core.converter.AbstractAzureMessageConverter.toMessage(AbstractAzureMessageConverter.java:83) ~[azure-spring-integration-core-2.9.0.jar:2.9.0]
	at com.azure.spring.integration.eventhub.impl.EventHubProcessor.onEvent(EventHubProcessor.java:74) ~[azure-spring-integration-eventhubs-2.9.0.jar:2.9.0]
	at com.azure.messaging.eventhubs.EventProcessorClientBuilder$1.processEvent(EventProcessorClientBuilder.java:595) ~[azure-messaging-eventhubs-5.10.1.jar:5.10.1]
	at com.azure.messaging.eventhubs.PartitionPumpManager.processEvent(PartitionPumpManager.java:274) ~[azure-messaging-eventhubs-5.10.1.jar:5.10.1]
	... 14 common frames omitted

To Reproduce

  • Use this sample;
  • Replace the dependencyManagement and dependencies as following:
<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>2020.0.3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-core</artifactId>
        <version>1.20.0</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>com.azure.spring</groupId>
      <artifactId>azure-spring-cloud-stream-binder-eventhubs</artifactId>
      <version>2.9.0</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <dependency>
      <groupId>org.hibernate.validator</groupId>
      <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  • Send message, curl -X POST http://localhost:8080/messages/imperative/staticalDestination?message=hello

Code Snippet

@Override
    protected Map<String, Object> buildCustomHeaders(EventData azureMessage) {
        Map<String, Object> headers = super.buildCustomHeaders(azureMessage);

        headers.putAll(getSystemProperties(azureMessage));

        Map<String, Object> properties = azureMessage.getProperties();
        if (properties.containsKey(NATIVE_HEADERS) && isValidJson(properties.get(NATIVE_HEADERS))) {
            String nativeHeader = (String) properties.remove(NATIVE_HEADERS);
            properties.put(NATIVE_HEADERS, readValue(nativeHeader, LinkedMultiValueMap.class));
        }
        headers.putAll(azureMessage.getProperties());
        return headers;
    }
```

**Expected behavior**
No exceptions and better the tracing information transfers normally.

**Setup (please complete the following information):**
 - OS: Windows
 - IDE: IntelliJ
 - Library/Libraries: com.azure.spring:azure-spring-cloud-stream-binder-eventhubs:2.9.0
 - Java version: 11
 - Frameworks: org.springframework.boot:spring-boot-starter-parent:2.5.4, org.springframework.cloud:spring-cloud-dependencies:2020.0.3

**Information Checklist**
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x] Bug Description Added
- [x] Repro Steps Added
- [x] Setup information Added
@moarychan moarychan added azure-spring All azure-spring related issues azure-spring-eventhubs Spring event hubs related issues. bug This issue requires a change to an existing behavior in the product in order to be resolved. labels Oct 8, 2021
@moarychan moarychan self-assigned this Oct 8, 2021
@moarychan moarychan added this to the [2021] November milestone Oct 11, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring All azure-spring related issues azure-spring-eventhubs Spring event hubs related issues. bug This issue requires a change to an existing behavior in the product in order to be resolved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant