URLConnection Segmentation Fault RasPi Console Web Service App

Hello all.

In a web service, I get Segmention fault when trying to send the data.

URLConnection.Send("PUT",URL_Path + LastCommandSent )

This only occurs on the pi, not when I test on windows. Is there any way I can narrow down what is wrong, or does anyone have an idea how to fix this?
Thanks,
Tim

Here are the results of running ldd… it appears OK.
pi@AxcysEmbeddedController:~/Public/axcys/AxcysClientService $ ldd axcysclientservice
linux-vdso.so.1 (0x7efe7000)
/usr/lib/arm-linux-gnueabihf/libarmmem.so (0x76f45000)
XojoConsoleFrameworkARM.so => /home/pi/Public/axcys/AxcysClientService/./axcysclientservice Libs/XojoConsoleFrameworkARM.so (0x74db0000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x74c5a000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x74c2d000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0x74c16000)
libgobject-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgobject-2.0.so.0 (0x74bbc000)
libglib-2.0.so.0 => /lib/arm-linux-gnueabihf/libglib-2.0.so.0 (0x74ab9000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x74a91000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0x74a7e000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x74a03000)
libunwind.so.8 => /usr/lib/arm-linux-gnueabihf/libunwind.so.8 (0x749c2000)
libunwind-arm.so.8 => /usr/lib/arm-linux-gnueabihf/libunwind-arm.so.8 (0x7497c000)
libc++.so.1 => /home/pi/Public/axcys/AxcysClientService/./axcysclientservice Libs/libc++.so.1 (0x7482a000)
/lib/ld-linux-armhf.so.3 (0x54b02000)
libffi.so.6 => /usr/lib/arm-linux-gnueabihf/libffi.so.6 (0x74812000)
libpcre.so.3 => /lib/arm-linux-gnueabihf/libpcre.so.3 (0x7479f000)
liblzma.so.5 => /lib/arm-linux-gnueabihf/liblzma.so.5 (0x74778000)

The error is thrown when the commands

URLConnection.Send("PUT",URL_Path + LastCommandSent )

Is executed, but only when the jSON data is empty

URLConnection.SetRequestContent(json.ToString,  "application/json")
URLConnection.Send("PUT",URL_Path + LastCommandSent )

Is that how it should normally be?

too much memory usage can cause segmentation fault.

Less than 1/2 of the physical memory is being used.

Only happens when executing this code- just found too that it occurs even when it is not null too…

URLConnection.Send("PUT",URL_Path + LastCommandSent )

Found ONE problem …
Was missing libsoup 2.4

sudo apt-get install libsoup2.4

Its still crashing with same error…
Interesting tho, is I tried 3 different pi’s. Two are copies of the first. The first works now that the libsoup2.4 is installed. However the other two pi’s continue to fail even after they had the libsoup installed…

Ideas anyone?

Bad sd card? (Swap memory is on SD)

I’ve seen this too with URLConnection and large result data or foldeitem in the result. I’m not sure why your memory shows what you are seeing.

Maybe the irlconnection goes out of scope?

Segementation fault could mean you access a memory address that’s not there (memoryblock out of bounds, string encoding, object destroyed etc)

Hi Derk.

Its all done in the same method and the URLConnection is a public property of the app. Does not appear out of scope. The amount of data is only a few kbytes and is identical on all three units.

As far as the mSD card is concerned, all three units are actively running other apps in real time, reading and writing to a db without issue. So I don’t think it is a mSD card issue.

All I am doing, is reading one or two records from a PostgreSQL database and sending that on via URLConnection. What is really blowing me away is that one our of three is now working once I found they were missing libsoup…

Tim

Well with http segmentation fault can happen (don’t think it should) when the Content-Length header is incorrect.

I don’t believe I am setting that (Content-Length header). How is that done? The only two lines of code I am using are:

URLConnection.SetRequestContent(json.ToString,  "application/json")
URLConnection.Send("PUT",URL_Path + LastCommandSent )

Thanks for your help Derk.
Tim

Is there an alternative to use URLConnection withouth changing too much of the code I have already written? This really seems like a waste of time at this point…

Tim

I found out that if the JSON string is long (don’t have a definition of what long really is) then it crashes. But if it is short it does not.

Long:

{"getActivitySummary":{"57":{"CID":11234,"SID":1234,"TamperEvents":"0","LastUpdatedDateTime":"2019-08-11 07:55:02","DateX":"2019-08-11  ","Todays_OtherAccessAttempt":"0","UnRecordedEvents":"0","Todays_PMS_Lockouts":"0","Todays_PMS_MoveIns":"0","Todays_PMS_MoveOuts":"0","LastAccessDateTime":"","Todays_PMS_Updates":"0","Todays_PMS_Lockout_Removals":"0","Todays_TamperEvents":"0","Todays_AlarmEvents":"0","Todays_DoorCloseEvents":"0","Todays_DoorOpenEvents":"0","Todays_EntryAttempts_Hours":"0","Todays_ExitAttempts_Hours":"0","Todays_Alarm_NotAssigned":"0","Todays_Alarm_NotEnabled":"0","Todays_EntryAttempts":"2","Todays_ExitAttempts":"2","Todays_InvalidCode":"0","Todays_EntryAttemptsLockedout":"0","Todays_ExitAttemptsLockedout":"0","Todays_EntryAttempts_ngPIN":"0","Todays_ExitAttempts_ngPIN":"0","Todays_PMS_PINChanges":"0","IP":"127.0.0.1","Mac":"0000","SystemStatus":"OK","Todays_AliveEvents ":"0","Todays_BattAlarmEvents":"0","Todays_StartupEvents":"0"}}}

Short:

{"DBError":"No Activity Data"}

So maybe there is an issue with the header? Any ideas???

Thanks again,
Tim

Do you catch exceptions?

I think it may be a bug but i’m still not sure how it happens, it does happen on the pi when the content is about 1kb or more.

No exceptions can be caught. I even added a try/catch scenario to that code and it already included exception handling/reporting before that…

It executes and crashes…
Tim