powered by Jive Software

SIGSEGV fault when connect() is called


#1

Hi all,

I am using Smack 4.3.0 in Android Studio 3.2.1 and intend to try different functions in Smack. I have started to simply connect to my XMPP server which is running and I can connect to it using any other XMPP client. I use the following code to connect to the server before calling “login()” function:

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(“user”, “pass_code”);
configBuilder.setXmppDomain(“192.168.1.187”);

AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
connection.connect();

When the above code is executed I always get SIGSEGV fault when “connect()” function is invoked with the following error message:

SIGSEGV (signal SIGSEGV: invalid address (fault address: 0xc))

Can anyone let me know why I get this error and why essentially the library should crash instead of throwing en exception?

Another question is that all documents in the repository are dated 2002-2008 and seem to be very outdated. Are these documents still valid? If yes, so why the date is misleading? If no, would you please let me know where can I find the latest document?

Regards,

Dan


#2

Attach a debugger and get a (C) backtrace to identify the culprit.

Please avoid asking unrelated questions in the same post.

The documentation should be up to date. What you are referring to is the copyright notice and Jive did not extend the time range.


#3

This is all I got from the debugger:

--------- beginning of crash

android.os.NetworkOnMainThreadException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:276)
at libcore.io.IoBridge.sendto(IoBridge.java:509)
at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:184)
at java.net.DatagramSocket.send(DatagramSocket.java:305)
at org.minidns.source.NetworkDataSource.queryUdp(NetworkDataSource.java:89)
at org.minidns.source.NetworkDataSource.query(NetworkDataSource.java:56)
at org.minidns.AbstractDnsClient.query(AbstractDnsClient.java:249)
at org.minidns.AbstractDnsClient.query(AbstractDnsClient.java:364)
at org.minidns.DnsClient.query(DnsClient.java:155)
at org.minidns.iterative.ReliableDnsClient.query(ReliableDnsClient.java:96)
at org.minidns.AbstractDnsClient.query(AbstractDnsClient.java:187)
at org.minidns.hla.ResolverApi.resolve(ResolverApi.java:113)
at org.minidns.hla.ResolverApi.resolve(ResolverApi.java:109)
at org.minidns.hla.ResolverApi.resolveSrv(ResolverApi.java:184)
at org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver.lookupSRVRecords0(MiniDnsResolver.java:74)
at org.jivesoftware.smack.util.dns.DNSResolver.lookupSRVRecords(DNSResolver.java:53)
at org.jivesoftware.smack.util.DNSUtil.resolveDomain(DNSUtil.java:155)
at org.jivesoftware.smack.util.DNSUtil.resolveXMPPServiceDomain(DNSUtil.java:115)
at org.jivesoftware.smack.AbstractXMPPConnection.populateHostAddresses(AbstractXMPPConnection.java:650)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(XMPPTCPConnection.java:559)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:895)
at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:409)

It doesn’t give me any hint. The only thing I am suspecting is the IP number that I use as server domain since apparently the DNS lookup fails but this is how my test platform is setup. I appreciate if anyone can help.


#4

Do you know when Android throws this type of Exception?


#5

I hope I have understood your question correctly. The minimum code that can re-produce this error in my configuration is:

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(“user”, “pass”);
configBuilder.setXmppDomain(“192.168.1.202”);

AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());

// Connect to the server
connection.connect();

// Log into the server
connection.login();
} catch (XmppStringprepException e) {
} catch (XMPPException e) {
} catch (SmackException.NotConnectedException e) {
} catch (InterruptedException e) {
} catch (SmackException e) {
} catch (IOException e) {
}

The program crashes exactly when “connection.connect()” is executed.

IMHO the library should not crash in any circumstances even with invalid parameters as input. I assume that it is actually Smack that crashed as the log shows that DNS lookup inside the library fails.

Thanks,

Danesh


#6

What you show is a method call throwing an Exception. The first thing you should do when a method throws on you is to understand why it does that. Android’s NetworkOnMainThreadException is pretty well documented, I suggest you read up on it.


#7

Hi,
Yes you are right! Thanks a lot for your hint. I used another thread to run the code and now it works. However, I still have problem with the certificates but I will ask in a separate thread.
Thanks again,
Dan