# Socket.dns.getaddrinfo() hangs an app (DEF-3486)

**URL:** <https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084>\
**Category:** Bugs\
**Created:** [September 11, 2018, 1:42pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084 "2018-09-11T13:42:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [September 11, 2018, 1:42pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084/1 "2018-09-11T13:42:16Z")

</div>

Reproduce step

1. run Network Link Conditioner (macos app)
2. set profile “100% loss” in Network Link Conditioner
3. create a project with one component that contain next code:

```lua
function init(self)
	print("before")
	socket.dns.getaddrinfo("amazon.com")
	print("after")
end

```

1. Try to build the project.

Application hangs when try to call getaddrinfo with bad connection or problems on a host side. It’s one of the reason of ANRs on Android.

I checked on macOS and Android.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [September 11, 2018, 1:51pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084/2 "2018-09-11T13:51:24Z")

</div>

Yes, reproduced here as well. Adding a Jira… DEF-3486

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [September 11, 2018, 3:54pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084/3 "2018-09-11T15:54:16Z")

</div>

When do you call socket.dns.getaddrinfo()? Is it called behind the scenes since you do a [socket.bind()](https://github.com/diegonehab/luasocket/blob/master/src/socket.lua#L29)?

This [ends up calling getaddrinfo()](https://github.com/diegonehab/luasocket/blob/master/src/inet.c#L162-L171) and from what I can tell it’s not possible to give that method call a timeout. Perhaps some kind of connectivity check should be done before trying to bind the socket?

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [September 11, 2018, 3:59pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084/4 "2018-09-11T15:59:56Z")

</div>

> [@britzl](#):
>
> This ends up calling getaddrinfo() and from what I can tell it’s not possible to give that method call a timeout. Perhaps some kind of connectivity check should be done before trying to bind the socket?

Yes, I am working on it right now. But I believed that it possible to fix internally for avoiding similar problems in future.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [September 11, 2018, 8:11pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084/5 "2018-09-11T20:11:35Z")

</div>

Hmm, yes, maybe it can be solved internally. But we’re talking about the LuaSocket code and the getaddrinfo() C-call which as far as I can tell is completely out of our control.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [September 11, 2018, 8:27pm UTC](https://forum.defold.com/t/socket-dns-getaddrinfo-hangs-an-app-def-3486/29084/6 "2018-09-11T20:27:53Z")

</div>

> [@britzl](#):
>
> Hmm, yes, maybe it can be solved internally. But we’re talking about the LuaSocket code and the getaddrinfo() C-call which as far as I can tell is completely out of our control.

Ok, no problem. I’ll avoid this by checking connectivity before.  
It’s an issue in gamesparks sdk, but I don’t know how to report to them, I’ll fix it locally.
