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

Crash when resolving IP address from hostname on macOS #80727

Open
aaronfranke opened this issue Aug 17, 2023 · 5 comments
Open

Crash when resolving IP address from hostname on macOS #80727

aaronfranke opened this issue Aug 17, 2023 · 5 comments

Comments

@aaronfranke
Copy link
Member

aaronfranke commented Aug 17, 2023

Godot version

Happens on The Mirror's fork of Godot, it's hard to reproduce so unsure about master but seems likely given there are not a ton of differences.

System information

macOS 13.4.1 on M1 Pro

Issue description

I am getting a crash on macOS when resolving IP addresses from hostnames using the macOS getaddrinfo method.

================================================================
handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] 1   libsystem_platform.dylib            0x0000000184362a24 _sigtramp + 56
[2] 2   Network                             0x000000018afd0e74 nw_path_snapshot_path + 48
[3] 3   Network                             0x000000018afd07b8 nw_path_evaluator_evaluate + 2832
[4] 4   Network                             0x000000018afcf5d4 nw_path_create_evaluator_for_endpoint + 108
[5] 5   Network                             0x000000018ae3e594 nw_nat64_v4_address_requires_synthesis + 252
[6] 6   libsystem_info.dylib                0x000000018437f23c _gai_nat64_second_pass + 280
[7] 7   libsystem_info.dylib                0x000000018436bca4 si_addrinfo + 1220
[8] 8   libsystem_info.dylib                0x000000018436b738 getaddrinfo + 168
[9] IPUnix::_resolve_hostname(List<IPAddress, DefaultAllocator>&, String const&, IP::Type) const (in godot.macos.editor.arm64) + 140
[10] IP::resolve_hostname_queue_item(String const&, IP::Type)
[11] _IP_ResolverPrivate::_thread_function(void*) (in godot.macos.editor.arm64) + 92
[12] Thread::callback(unsigned long long, Thread::Settings const&, void (*)(void*), void*) (in godot.macos.editor.arm64) + 120
[13] Thread::~Thread()
[14] 14  libsystem_pthread.dylib             0x0000000184333fa8 _pthread_start + 148
[15] 15  libsystem_pthread.dylib             0x000000018432eda0 thread_start + 8
-- END OF BACKTRACE --

The crashing code is here:

	hints.ai_flags &= ~AI_NUMERICHOST;

	// before crash
	int s = getaddrinfo(p_hostname.utf8().get_data(), nullptr, &hints, &result);
	// after crash
	if (s != 0) {
		print_verbose("getaddrinfo failed! Cannot resolve hostname.");
		return;
	}

I have used print statements to verify that the p_hostname.utf8().get_data() value we are passing in is indeed a valid string. My suspicion is that this is a bug with macOS, but I am not sure. Even if this is a bug in macOS, it may be helpful to have an issue open to track this bug.

Steps to reproduce

Call this method on macOS and it will randomly crash. It only happens a tiny fraction of the time, a few percent or less, so unfortunately it's very hard to reproduce.

Minimal reproduction project

Unfortunately since it's so hard to reproduce, I have not been able to reproduce the crash once with the minimal reproduction project (either using master or The Mirror's fork), but here is an attempt at a minimal reproduction project anyway: IP_resolver_getaddrinfo_crash.zip

Since IPUnix is not exposed you also need to use these engine changes. If you instead use IP directly then it will cache the result so the test will only run on one frame.

@Sch1nken
Copy link
Contributor

I can test tomorrow on MacOS 13.2.1 (also M1 Pro). A completely random guess but worth a shot: Do you use the Apple iCloud Private Relay? (I believe it gets sort of auto enabled when you login with an icloud account). Might not be it, but who knows.

Anyways, I'll try to test tomorrow after work.

@aaronfranke
Copy link
Member Author

@Sch1nken I do not use that.

@RevoluPowered
Copy link
Contributor

We should write up a unit test for this and we can run it 10000 times or something and it should be caught on the MacOS runner

@RevoluPowered
Copy link
Contributor

I wrote a unit test for this method, we might need to bump the numbers up until it fails. :)

@aaronfranke
Copy link
Member Author

I wonder if it's possible that the bug only happens with multiple threads calling this method at once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants