question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unity clients fail with IL2CPP builds

See original GitHub issue

Update: The problem is with Unity. See https://github.com/nats-io/nats.net/issues/361#issuecomment-581632837 (below) for a workaround…

Update 2: The workaround doesn’t work, at least on iOS devices.

Update 3: Got it to work. See https://github.com/nats-io/nats.net/issues/361#issuecomment-593048632 (below)…

Update 4: It still fails sometimes even when the UseOldRequestStyle option is true.

Update 5: The problem has been solved. See: https://github.com/nats-io/nats.net/pull/370

I have a Unity project using NATS that works fine if built using Mono on Android or if using IL2CPP development build. If built as a release build with IL2CPP for Android or iOS, the NATS connection disconnects on the second request/reply and attempts to reconnect.

This appears to be similar to issue #358.

Here’s the NATS server log…

[8125] 2020/01/27 10:19:42.095095 [DBG] 66.60.161.134:40560 - cid:9 - Client connection created
[8125] 2020/01/27 10:19:42.158135 [TRC] 66.60.161.134:40560 - cid:9 - <<- [CONNECT {"verbose":false,"pedantic":false,"user":"","pass":"[REDACTED]","ssl_required":false,"name":"","auth_token":"","lang":".NET","version":"0.0.1","protocol":1,"jwt":"","nkey":"","sig":"","echo":false}]
[8125] 2020/01/27 10:19:42.158195 [TRC] 66.60.161.134:40560 - cid:9 - <<- [PING]
[8125] 2020/01/27 10:19:42.158216 [TRC] 66.60.161.134:40560 - cid:9 - ->> [PONG]
[8125] 2020/01/27 10:19:42.359824 [TRC] 66.60.161.134:40560 - cid:9 - <<- [SUB _INBOX.ec2db33d7faf4825ad7bba87047defaf.*  1]
[8125] 2020/01/27 10:19:42.359986 [TRC] 66.60.161.134:40560 - cid:9 - <<- [PUB Citizen.Login _INBOX.ec2db33d7faf4825ad7bba87047defaf.1 15]
[8125] 2020/01/27 10:19:42.360003 [TRC] 66.60.161.134:40560 - cid:9 - <<- MSG_PAYLOAD: ["\x92\xa4Frog\xa8blobblob"]
[8125] 2020/01/27 10:19:42.360016 [TRC] 127.0.0.1:45964 - cid:1 - ->> [MSG Citizen.Login 2 _INBOX.ec2db33d7faf4825ad7bba87047defaf.1 15]
[8125] 2020/01/27 10:19:42.361726 [TRC] 127.0.0.1:45964 - cid:1 - <<- [PONG]
[8125] 2020/01/27 10:19:42.361753 [TRC] 127.0.0.1:45964 - cid:1 - <<- [PUB _INBOX.ec2db33d7faf4825ad7bba87047defaf.1 11]
[8125] 2020/01/27 10:19:42.361767 [TRC] 127.0.0.1:45964 - cid:1 - <<- MSG_PAYLOAD: ["\x92\x00\xcf\x01\xf7\xf3w\xe6\x00\x00\x00"]
[8125] 2020/01/27 10:19:42.361786 [TRC] 66.60.161.134:40560 - cid:9 - ->> [MSG _INBOX.ec2db33d7faf4825ad7bba87047defaf.1 1 11]
[8125] 2020/01/27 10:19:42.804264 [TRC] 66.60.161.134:40560 - cid:9 - <<- [SUB Avatar.Pose.test  2]
[8125] 2020/01/27 10:19:42.804320 [TRC] 66.60.161.134:40560 - cid:9 - <<- [SUB Avatar.Select.test  3]
[8125] 2020/01/27 10:19:42.804352 [TRC] 66.60.161.134:40560 - cid:9 - <<- [SUB Prop.OnAdd.test  4]
[8125] 2020/01/27 10:19:42.804365 [TRC] 66.60.161.134:40560 - cid:9 - <<- [SUB Prop.OnMove.test  5]
[8125] 2020/01/27 10:19:42.804380 [TRC] 66.60.161.134:40560 - cid:9 - <<- [SUB Prop.OnRemove.test  6]
[8125] 2020/01/27 10:19:42.911325 [TRC] 66.60.161.134:40560 - cid:9 - <<- [PUB Prop.Look.test _INBOX.ec2db33d7faf4825ad7bba87047defaf.2 10]
[8125] 2020/01/27 10:19:42.911356 [TRC] 66.60.161.134:40560 - cid:9 - <<- MSG_PAYLOAD: ["\x91\xcf\x01\xf7\xf3w\xe6\x00\x00\x00"]
[8125] 2020/01/27 10:19:42.911371 [TRC] 127.0.0.1:46110 - cid:2 - ->> [MSG Prop.Look.test 2 _INBOX.ec2db33d7faf4825ad7bba87047defaf.2 10]
[8125] 2020/01/27 10:19:42.914473 [TRC] 127.0.0.1:46110 - cid:2 - <<- [PONG]
[8125] 2020/01/27 10:19:42.914499 [TRC] 127.0.0.1:46110 - cid:2 - <<- [PUB _INBOX.ec2db33d7faf4825ad7bba87047defaf.2 74]
[8125] 2020/01/27 10:19:42.914518 [TRC] 127.0.0.1:46110 - cid:2 - <<- MSG_PAYLOAD: ["\x92\x00\x81\xcf\x01\xeao_\x93\x01\x00\x00\x92\x02\x95\x93\xca\x00\x00\x00\x00\xca\x00\x00\x00\x00\xca\x00\x00\x00\x00\x94\xca\x00\x00\x00\x00\xca\x00\x00\x00\x00\xca\x00\x00\x00\x00\xca?\x80\x00\x00\xacTrackedImage\xa3Bar\xca>L\xcc\xcd"]
[8125] 2020/01/27 10:19:42.914534 [TRC] 66.60.161.134:40560 - cid:9 - ->> [MSG _INBOX.ec2db33d7faf4825ad7bba87047defaf.2 1 74]
[8125] 2020/01/27 10:19:42.967805 [DBG] 66.60.161.134:40560 - cid:9 - Client connection closed
[8125] 2020/01/27 10:19:42.967893 [TRC] 66.60.161.134:40560 - cid:9 - <-> [DELSUB 1]
[8125] 2020/01/27 10:19:42.967910 [TRC] 66.60.161.134:40560 - cid:9 - <-> [DELSUB 2]
[8125] 2020/01/27 10:19:42.967933 [TRC] 66.60.161.134:40560 - cid:9 - <-> [DELSUB 3]
[8125] 2020/01/27 10:19:42.967939 [TRC] 66.60.161.134:40560 - cid:9 - <-> [DELSUB 4]
[8125] 2020/01/27 10:19:42.967944 [TRC] 66.60.161.134:40560 - cid:9 - <-> [DELSUB 5]
[8125] 2020/01/27 10:19:42.967950 [TRC] 66.60.161.134:40560 - cid:9 - <-> [DELSUB 6]
[8125] 2020/01/27 10:19:43.241501 [DBG] 66.60.161.134:40562 - cid:10 - Client connection created
[8125] 2020/01/27 10:19:43.285678 [TRC] 66.60.161.134:40562 - cid:10 - <<- [CONNECT {"verbose":false,"pedantic":false,"user":"","pass":"[REDACTED]","ssl_required":false,"name":"","auth_token":"","lang":".NET","version":"0.0.1","protocol":1,"jwt":"","nkey":"","sig":"","echo":false}]
[8125] 2020/01/27 10:19:43.285773 [TRC] 66.60.161.134:40562 - cid:10 - <<- [PING]
[8125] 2020/01/27 10:19:43.285788 [TRC] 66.60.161.134:40562 - cid:10 - ->> [PONG]
[8125] 2020/01/27 10:19:43.352220 [TRC] 66.60.161.134:40562 - cid:10 - <<- [SUB _INBOX.ec2db33d7faf4825ad7bba87047defaf.*  1]
[8125] 2020/01/27 10:19:43.352270 [TRC] 66.60.161.134:40562 - cid:10 - <<- [SUB Avatar.Pose.test  2]
[8125] 2020/01/27 10:19:43.352300 [TRC] 66.60.161.134:40562 - cid:10 - <<- [SUB Avatar.Select.test  3]
[8125] 2020/01/27 10:19:43.352309 [TRC] 66.60.161.134:40562 - cid:10 - <<- [SUB Prop.OnAdd.test  4]
[8125] 2020/01/27 10:19:43.352374 [TRC] 66.60.161.134:40562 - cid:10 - <<- [SUB Prop.OnMove.test  5]
[8125] 2020/01/27 10:19:43.352406 [TRC] 66.60.161.134:40562 - cid:10 - <<- [SUB Prop.OnRemove.test  6]
[8125] 2020/01/27 10:19:43.444747 [TRC] 66.60.161.134:40562 - cid:10 - <<- [PING]
[8125] 2020/01/27 10:19:43.444806 [TRC] 66.60.161.134:40562 - cid:10 - ->> [PONG]
[8125] 2020/01/27 10:19:45.450564 [DBG] 66.60.161.134:40562 - cid:10 - Client Ping Timer
[8125] 2020/01/27 10:19:45.450651 [TRC] 66.60.161.134:40562 - cid:10 - ->> [PING]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:29 (28 by maintainers)

github_iconTop GitHub Comments

2reactions
Britvichcommented, Feb 3, 2020

With the help of @ColinSullivan1 we were able to determine that Unity has a problem with their implementation of ConcurrentDictionary on IL2CPP builds. Since NATS uses ConcurrentDictionary, Unity IL2CPP builds with NATS won’t work.

I have opened a ticket with Unity at:

https://fogbugz.unity3d.com/default.asp?1216719_re63en8l0g4mhcsp

Even this simple example crashes Unity:

using System.Collections.Concurrent;
using UnityEngine;

public class Startup : MonoBehaviour {
	void Start() {
		var x = new ConcurrentDictionary<int, int>().Values;
	}
}

Workaround: If you build with the mono libraries, it works fine. If you need to build an IL2CPP version, changing the ConcurrentDictionary to a Dictionary based version of Conn.cs works:

Line 132 becomes:

private Dictionary<Int64, Subscription> subs = new Dictionary<Int64, Subscription>();

Line 3063 becomes:

if (!subs.ContainsKey(s.sid))
	return;
o = subs[s.sid];
subs.Remove(s.sid);

Line 3578 becomes:

public int SubscriptionCount {
	get {
		lock (mu) {
			return subs.Count;
		}
	}
}

Line 3646 adds:

lock (mu) {

Line 3673 adds:

}
1reaction
Britvichcommented, Feb 7, 2020

For those wanting to upvote this problem, it’s now also on Unity’s issue tracker at:

https://issuetracker.unity3d.com/issues/anroid-logcat-throws-advapi32-related-warning-when-using-concurrentdictionary-in-il2cpp-builds

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when building IL2CPP (2020.3.15f2, Windows 11)
Hi everyone, I'm getting an error when building with IL2CPP that I'm having a hard time figuring out: I had a few errors...
Read more >
Unity server built with IL2CPP fails
Has anyone here had any luck running a Linux server build, created from Unity using IL2CPP? I currently have a mono-based build working...
Read more >
Unity 2021.3.10f IL2CPP build error, failed with output
I have been trying to resolve this thing for a while, still not having any progress, can anyone help me out, big thks...
Read more >
Unity fails to build due to IL2CPP
Unity fails to build due to IL2CPP · It seems that the armcc can't find a proper licence and therefore does not build...
Read more >
IL2CPP Overview
The IL2CPP (Intermediate Language To C++) scripting backendA framework that powers scripting in Unity. Unity supports three different scripting backends ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found