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

DFU fails with NegativeArraySizeException: Data length is negative (-2 bytes) and report a different MTU value #211

Open
Endhuine opened this issue Jan 2, 2025 · 1 comment
Labels
question Further information is requested

Comments

@Endhuine
Copy link

Endhuine commented Jan 2, 2025

Hi.
I’m encountering an issue reported by some of our users when attempting a DFU. The application intermittently crashes with the following exception:

java.lang.NegativeArraySizeException: Data length is negative (-2 bytes) (MTU = 69, CBOR overhead = 71, data length = 211750, offset = 0)

What is odd is that we log the MTU value of our connection and its value is the one we use for negotiation: 72 (log below)

2025-01-02 07:11:44.433 🟪 VERBOSE - (pool35thread1:478): AppState(
        ...,
	carvDevicesState: CarvDevicesState(
		left: CarvDeviceState(
			side=left
			rxBleDevice.macAddress=##:##:##:##:##:##
			rxBleConnection.mtu=72
			connectionState=Connected(authorized=true), 
			...
		)
		right: CarvDeviceState(
			side=right
			isReadyToRecord=false
			rxBleDevice.macAddress=##:##:##:##:##:##
			rxBleConnection.mtu=72
			connectionState=Connected(authorized=true), 
			...
		)
	)
2025-01-02 07:11:44.433 🟥 ERROR   - (pool35thread1:478): Uncaught exception on thread pool-35-thread-1
java.lang.NegativeArraySizeException: Data length is negative (-2 bytes) (MTU = 69, CBOR overhead = 71, data length = 211750, offset = 0)
	at io.runtime.mcumgr.managers.ImageManager.e(ImageManager.java:243)
	at Gq.f.a(Upload.java:14)
	at io.runtime.mcumgr.transfer.TransferCallable.a(TransferCallable.java:70)
	at Gq.d.run(TransferManager.java:3)
	at Gq.d.run(TransferManager.java:53)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
	at java.lang.Thread.run(Thread.java:1012)

Additional Context

  • Restarting the update usually resolves the issue temporarily.
  • I have not been able to reproduce this issue consistently.

Do you happen to have any suggestions on how to debug or fix this issue?

Thank you!

@philips77
Copy link
Member

Hello,
As the error says, you need to increase the MTU. Seems like your device returns 69 (at least sometimes?).

You can do this in 2 ways:

  1. Increase the maximum ATT MTU on the device to 71+, preferably 498.
  2. Enable segmentation and reassembly on the device and "MCU Mgr Params" command in SMP Server. This allows the device to buffer long SMP packets split into smaller chunks.

@philips77 philips77 added the question Further information is requested label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants