Android Question How to find out what is causing AStream_Terminated

RJB

Active Member
Licensed User
Longtime User
I suspect I have changed something and caused the problem myself but can't find out what!
I'm sending/ receiving from B4a to B4r and every 10 or 20 seconds a get AStream_Terminated and the transmission is interrupted.
I've tried everything obvious (timers, log messages, the remote esp32 code etc.) but found nothing.
LastException doesn't help as it only shows the exception occurred before the AStream_Terminated not the one that caused it.
Unfilterred logs show various combinations of:

B4X:
CPU update time < 2.5sec
[CDS]close[47129]
threadid=17: exiting
threadid=18: exiting
threadid=17: bye!
07:33:47 SendAstream Terminated***********************************
threadid=18: bye!


[CDS]close[32779]
threadid=17: exiting
threadid=17: bye!
threadid=18: exiting
threadid=18: bye!
07:33:57 SendAstream Terminated***********************************


CPU update time < 2.5sec
CPU update time < 2.5sec
[CDS]close[57613]
threadid=17: exiting
threadid=17: bye!
threadid=18: exiting
threadid=18: bye!
07:34:17 SendAstream Terminated***********************************
adb fdevent_process list (15) (18)

around the failure, which means nothing to me.

Is there any way to find out what is causing the termination?

Thanks
 

RJB

Active Member
Licensed User
Longtime User
I have no idea what the threads are!! I haven't, knowingly, created them.
Is there any way of identifying what created them, library or whatever?
Thanks
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Here's a longer section of the unfiltered logs, if that helps?
B4X:
getNetworkBasedCountry: null
getLastKnownLocationBasedCountry: null
getSimCountryIso simId = 0prop = gb
getSimBasedCountry: GB
Country {ISO=GB, source=2, time=518497}
Country {ISO=GB, source=0, time=457465} --> Country {ISO=GB, source=2, time=518497}
 from settings cache , name = sms_default_application , value = com.android.mms
Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
 from settings cache , name = airplane_mode_on , value = 0
getContentProviderImpl: from callerandroid.app.ApplicationThreadProxy@422d0ab8 (pid=3463) to get content provider telephony
startLocationBasedDetection=true detectCountry=(source: 2, countryISO: GB) isAirplaneModeOff()=true mListener=com.android.server.CountryDetectorService$1@4263d1e0 isGeoCoderImplemnted()=true
Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
 from settings cache , name = airplane_mode_on , value = 0
run startLocationBasedDetector()
hoder:android.app.IActivityManager$ContentProviderHolder@41e1e550,provider,holder.Provider:android.content.ContentProviderProxy@41e1eb98
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
+IsAPBTLoopbackWithCodec(), mBtLoopbackWithCodec = 0
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
+IsAPBTLoopbackWithCodec(), mBtLoopbackWithCodec = 0
create interp thread : stack size=128KB
create new thread
new thread created
update thread list
threadid=18: interp stack at 0x62cb3000
threadid=18: created from interp
start new thread
threadid=18: notify debugger
threadid=18 (Thread-292): calling run()
create interp thread : stack size=128KB
create new thread
new thread created
update thread list
[CDS]close[46890]
threadid=19: interp stack at 0x62cd3000
threadid=19: created from interp
start new thread
threadid=18: exiting
threadid=18: bye!
1728396765041: 15:12:45 SendAstream Terminated****Not last exception******: (Exception) Not initialized
false : true : true
15:12:45: ASNR failed write, buffer full?: 192.168.1.83 : 0
threadid=19: notify debugger
threadid=19 (Thread-293): calling run()
threadid=19: exiting
threadid=19: bye!
getActiveNetworkInfo:NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "TALKTALK437380", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false, simId: 0/10148
[socket][7] connection /192.168.1.83:21216;LocalPort=51062(30000)
[CDS]connect[/192.168.1.83:21216] tm:30
[Posix_connect Debug]Process com.AdzDisplay.AdzMicroControl :21216
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
+IsAPBTLoopbackWithCodec(), mBtLoopbackWithCodec = 0
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
+IsAPBTLoopbackWithCodec(), mBtLoopbackWithCodec = 0
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
+IsAPBTLoopbackWithCodec(), mBtLoopbackWithCodec = 0
create interp thread : stack size=128KB
create new thread
new thread created
update thread list
threadid=18: interp stack at 0x62cb3000
threadid=18: created from interp
start new thread
threadid=18: notify debugger
threadid=18 (Thread-292): calling run()
create interp thread : stack size=128KB
create new thread
new thread created
update thread list
[CDS]close[46890]
threadid=19: interp stack at 0x62cd3000
threadid=19: created from interp
start new thread
threadid=18: exiting
threadid=18: bye!
1728396765041: 15:12:45 SendAstream Terminated****Not last exception******: (Exception) Not initialized
false : true : true
15:12:45: ASNR failed write, buffer full?: 192.168.1.83 : 0
threadid=19: notify debugger
threadid=19 (Thread-293): calling run()
threadid=19: exiting
threadid=19: bye!
getActiveNetworkInfo:NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "TALKTALK437380", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false, simId: 0/10148
[socket][7] connection /192.168.1.83:21216;LocalPort=51062(30000)
[CDS]connect[/192.168.1.83:21216] tm:30
[Posix_connect Debug]Process com.AdzDisplay.AdzMicroControl :21216
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
+IsAPBTLoopbackWithCodec(), mBtLoopbackWithCodec = 0
AudioMTKStreamOut::write (-)
AudioResamplerMtk::resample() can't get buffer
reset
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Hard to say what causes the disconnection. Are you also handling AStream_Error?
Make sure that you aren't closing the stream by mistake.

My guess is that the ESP32 closes the connection for some reason.

I don't know what is your use case, but I prefer not to maintain an open connection and instead make a connection - send message - receive response - disconnect. Similar to simple http requests. In many cases it is simpler than trying to keep the connection alive and monitor its state all the time.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Astream_Error is handled but is never called.
I've checked every close and added a log message before each one and can't find any correlation

I've just noticed that I disabled the socket.close after each received message at the esp32 end on 30th September. That may have been as part of trying to find the problem (or possible the cause of it!) but I will re-enable it and see what happens.
I am testing with one esp32 at the moment but there can be many with a 'ping' sent to each in turn so the connection is taken down after each response but again I will re-check.

I have to go into hospital for the day tomorrow so it might be a couple of days before I can get back with the results.

Thanks
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Just to complete the story: Not being able to locate what exactly was causing the problem I have rewritten large sections of the code at both ends and now have it working as it previously was. I can't say that I know what the cause or solution was but with the updated versions the 'pings' are now reliable and sending multiple jpeg files works as it did previously.
I'm sure it would have helped if the 'AStream_Terminated' provided some information as to what was causing the problem, but perhaps that's not possible?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…