B4J Question Socket Closed Error

tufanv

Expert
Licensed User
Hello,

I am running a non ui app on my vps to download a data from remote server and process that data to my database ( the db running on the same server with java app ) via a php file.

First step that downloads data from remote never gives an error , but randomly the second steps gives the following error , there are no patterns , sometimes it gives error 20 out of 25 tries and i cant fix the problem



The error is repating with the following error: I am not familiar much so do you have any idea what may cause it ? The interesting thing is i get this error not while getting the data from remote server but while calling the php file on the same sserver of java app to process to database. I always get basarisiz2 in the logs which is the job fail of calling the local php for the job: datayolla

this is my code:

B4X:
Sub Process_Globals
    Dim timeryenile As Timer
    Dim csu As CallSubUtils
End Sub

Sub AppStart (Args() As String)
    veri_al



    timerayarla
    StartMessageLoop
End Sub
Sub JobDone(Job As HttpJob)



        If Job.JobName="j" Then
            If Job.Success Then
                            'Log(Job.GetString)
                Dim anne As String = Job.GetString
                '    Log(Job.GetSize/1000)
   



       
                Dim yolla As HttpJob
                yolla.Initialize("datayolla", Me)
                yolla.PostString("http:/myserver/foreks.php","action=1&data="&anne)
                yolla.GetRequest.Timeout=2000
           
       
       
   
            Else
                csu.CallSubPlus(Me,veri_al,1000)
                Log("basarisiz1" & DateTime.Date(DateTime.Now))
       
            End If

        End If

        If Job.JobName="datayolla" Then
            If Job.Success Then
                timeryenile.Enabled=True
            Else
                Dim yolla As HttpJob
                yolla.Initialize("datayolla", Me)
                yolla.PostString("http:/myserver/foreks.php","action=1&data="&anne)
                yolla.GetRequest.Timeout=2000
       
                Log("basarisiz2" & Job.ErrorMessage)
                   
                   
            End If
            '            Log(Job.GetString)
   
   
       
        End If
        Job.Release



End Sub
Sub timeryenile_tick
    Try
        Dim gun As Int = DateTime.GetDayOfWeek(DateTime.Now)
   
        If gun=1 Or gun = 7 Then
            timeryenile.Interval=1800000 'her yarim saat
        Else
            timeryenile.Interval=1000
        End If
   
   
   
   
   
        timeryenile.Enabled=False
        veri_al

    Catch
        Log(LastException.Message)
    End Try
End Sub
Sub timerayarla
    timeryenile.Initialize("timeryenile","1000")
    timeryenile.Enabled=False
End Sub
Sub veri_al

    Dim j As HttpJob
    j.Initialize("j", Me)
    j.Download("http://remoteserverishere")
End Sub

B4X:
nohup: ignoring input
java.net.SocketTimeoutException: timeout
    at okio.Okio$4.newTimeoutException(Okio.java:227)
    at okio.AsyncTimeout.exit(AsyncTimeout.java:284)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:240)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:325)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:314)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:210)
    at okhttp3.internal.http1.Http1Codec.readResponse(Http1Codec.java:191)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:132)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:54)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
    at okhttp3.RealCall.execute(RealCall.java:63)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.executeWithTimeout(OkHttpClientWrapper.java:156)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.access$0(OkHttpClientWrapper.java:153)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$ExecuteHelper.run(OkHttpClientWrapper.java:201)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:183)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at okio.Okio$2.read(Okio.java:138)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:236)
 
Last edited:

tufanv

Expert
Licensed User
What do you mean with java app? B4J app?

Based on the error, the timeout value is too short.
yes b4j app , timeout value is not short indeed if we think that , the job is only calling a php file on the same machine . Am I wrong ?
 
Upvote 0

tufanv

Expert
Licensed User
Based on the error message, 2 seconds, is not enough.
I can make it 30 seconds for example but the data has to be updated every 2 seconds normally , and this error just happens sometimes , sometimes no problem happens. What I cant understand is While downloading a data from remote server 2 seconds is enough but not while calling a local php file. There must be a mistake by me in somewhere but i cant find it. if i set timeout to a higher value , processing of data will be very long like and normally it should take some miliseconds to deliver a 10 kb data to a php file.
 
Upvote 0

tufanv

Expert
Licensed User
PHP can be slow. Switch to B4J and it will run faster...
I use poststring , is the timeout value just for downloading the php or it also includes the things being done in php ? I mean lets say i send a data to php and inside php other things are being done , is the timeout value just for sending the data or for all the processes ? If it is for just sending the data it is too weird. I set it to 5 seconds and still problems
 
Upvote 0

DonManfred

Expert
Licensed User
Upvote 0

tufanv

Expert
Licensed User
What does the php do?
Requesting data from a 3rd party website? And the website does respond "in time"? Means; It is FAST responsing the result?
I get the data from remote server woth b4j app and send it to php, php parses the data and updates the values in my database . What i cant understand is , timeout problem only occurs between 08.30 gmt to 12 gmt , other than these hours there are no problems , people say that maybe peak times results in slowness but that is not the case because no problem with getting the data from remote , problem only happens in local things like calling the php and updating the data in database.
 
Upvote 0

tufanv

Expert
Licensed User
Maybe peak-time at your provider where the php is running.
But php provider is also where the b4j app is running and also the database os there , so peak times should not affect it. . At those times i ping the php files host and it gives bery very fast results.
 
Upvote 0

tufanv

Expert
Licensed User
the real important thing is tje job must be completed in 2 seconds because the data has to be updated every 2 seconds. I added some more logging to b4j app which send the data to php , job completion times are interesting. The problem only happens at 08.00 GMT and 12.00 GMT . For example for the last 5 minutes these are the job completeion times of the job which send data to php :

B4X:
Success. Datetime:08:54:38 Job Completed in:23.316Seconds
Success. Datetime:08:54:40 Job Completed in:0.672Seconds
Success. Datetime:08:54:41 Job Completed in:0.256Seconds
Success. Datetime:08:54:43 Job Completed in:0.226Seconds
Success. Datetime:08:55:05 Job Completed in:19.392Seconds
Success. Datetime:08:55:07 Job Completed in:0.27Seconds
Success. Datetime:08:55:30 Job Completed in:20.052Seconds
Success. Datetime:08:55:32 Job Completed in:0.663Seconds
Success. Datetime:08:55:33 Job Completed in:0.244Seconds
Success. Datetime:08:55:35 Job Completed in:0.333Seconds
Success. Datetime:08:55:58 Job Completed in:19.695Seconds
Success. Datetime:08:55:59 Job Completed in:0.254Seconds
Success. Datetime:08:56:22 Job Completed in:19.899Seconds
Success. Datetime:08:56:24 Job Completed in:0.25Seconds
Success. Datetime:08:56:25 Job Completed in:0.243Seconds
Success. Datetime:08:56:27 Job Completed in:0.329Seconds
Success. Datetime:08:56:50 Job Completed in:19.653Seconds
Success. Datetime:08:56:51 Job Completed in:0.266Seconds
Success. Datetime:08:57:16 Job Completed in:21.243Seconds
Success. Datetime:08:57:17 Job Completed in:0.251Seconds
Success. Datetime:08:57:19 Job Completed in:0.257Seconds
Success. Datetime:08:57:20 Job Completed in:0.234Seconds
Success. Datetime:08:57:47 Job Completed in:23.022Seconds
Success. Datetime:08:58:17 Job Completed in:27.203Seconds
Success. Datetime:08:58:19 Job Completed in:0.237Seconds
Success. Datetime:08:58:20 Job Completed in:0.239Seconds
Success. Datetime:08:58:22 Job Completed in:0.246Seconds
Success. Datetime:08:58:48 Job Completed in:21.991Seconds
Success. Datetime:08:58:49 Job Completed in:0.243Seconds
Success. Datetime:08:59:14 Job Completed in:21.851Seconds
Success. Datetime:08:59:16 Job Completed in:0.23Seconds
Success. Datetime:08:59:17 Job Completed in:0.227Seconds
Success. Datetime:08:59:45 Job Completed in:24.592Seconds

Failed. Datetime:09:00:00 Job Completed in:12.366Seconds

Failed. Datetime:09:00:00 Job Completed in:0Seconds
Success. Datetime:09:00:02 Job Completed in:0Seconds
Success. Datetime:09:00:08 Job Completed in:4.118Seconds
Success. Datetime:09:00:09 Job Completed in:0.002Seconds
Success. Datetime:09:00:11 Job Completed in:0.172Seconds
Success. Datetime:09:00:12 Job Completed in:0.002Seconds
Success. Datetime:09:00:13 Job Completed in:0.039Seconds
Success. Datetime:09:00:15 Job Completed in:0.306Seconds
Success. Datetime:09:00:17 Job Completed in:0.268Seconds
Success. Datetime:09:00:41 Job Completed in:21.771Seconds
Success. Datetime:09:00:43 Job Completed in:0.289Seconds
Success. Datetime:09:01:11 Job Completed in:24.539Seconds
Success. Datetime:09:01:13 Job Completed in:0.386Seconds
Success. Datetime:09:01:14 Job Completed in:0.387Seconds
Success. Datetime:09:01:16 Job Completed in:0.267Seconds
Success. Datetime:09:01:17 Job Completed in:0.353Seconds

Failed. Datetime:09:01:49 Job Completed in:27.84Seconds
Success. Datetime:09:01:49 Job Completed in:0Seconds
Success. Datetime:09:01:51 Job Completed in:0.688Seconds

Failed. Datetime:09:02:22 Job Completed in:27.816Seconds
Success. Datetime:09:02:22 Job Completed in:0Seconds
Success. Datetime:09:02:28 Job Completed in:3.691Seconds
Success. Datetime:09:02:30 Job Completed in:0.605Seconds
Success. Datetime:09:02:31 Job Completed in:0.232Seconds
Success. Datetime:09:02:33 Job Completed in:0.312Seconds
Success. Datetime:09:02:34 Job Completed in:0.273Seconds
Success. Datetime:09:02:36 Job Completed in:0.243Seconds

Failed. Datetime:09:03:08 Job Completed in:27.81Seconds
Success. Datetime:09:03:08 Job Completed in:0Seconds
Success. Datetime:09:03:38 Job Completed in:26.583Seconds
Success. Datetime:09:03:42 Job Completed in:2.316Seconds
Success. Datetime:09:03:46 Job Completed in:2.196Seconds

Failed. Datetime:09:04:17 Job Completed in:27.887Seconds
Success. Datetime:09:04:17 Job Completed in:0Seconds
Success. Datetime:09:04:21 Job Completed in:1.71Seconds
Success. Datetime:09:04:51 Job Completed in:27.241Seconds
Success. Datetime:09:04:56 Job Completed in:2.642Seconds
Success. Datetime:09:04:57 Job Completed in:0.259Seconds

Failed. Datetime:09:05:29 Job Completed in:27.893Seconds
Success. Datetime:09:05:29 Job Completed in:0Seconds
Success. Datetime:09:05:32 Job Completed in:1.219Seconds
Success. Datetime:09:05:33 Job Completed in:0.275Seconds

Failed. Datetime:09:06:05 Job Completed in:27.83Seconds
Success. Datetime:09:06:05 Job Completed in:0Seconds
Success. Datetime:09:06:09 Job Completed in:2.656Seconds
Success. Datetime:09:06:11 Job Completed in:0.28Seconds
Success. Datetime:09:06:14 Job Completed in:2.05Seconds
Success. Datetime:09:06:16 Job Completed in:0.422Seconds

Failed. Datetime:09:06:47 Job Completed in:28.082Seconds
Success. Datetime:09:06:48 Job Completed in:0Seconds

Failed. Datetime:09:07:19 Job Completed in:27.787Seconds
Success. Datetime:09:07:19 Job Completed in:0Seconds
Success. Datetime:09:07:23 Job Completed in:2.484Seconds
Success. Datetime:09:07:25 Job Completed in:0.41Seconds
Success. Datetime:09:07:30 Job Completed in:3.205Seconds

as you can see there are big flactuations , and I totally disabled the timeout value which at the 28th second fails automaticly. I also send this to vps provider.

other than 09.00 GMT and 12.00 GMT job always gets completed in 0.5 seconds at most. but between this times as you can see it starts to icnrease and at the peak time around 09.00 GMT it goes up to 28 seconds .
 
Upvote 0

tufanv

Expert
Licensed User
The problem (or issue) is most probably in the Apache(?) server.

Switch to B4J. You will get better performance.
How should I use the b4j app to update the databases instead of sending the data to php and make the db changes in php ?

Currently I am sending the downloaded data in b4j app to a php file and php file handles the database operations. How can directly connect to database and add or update db rows with b4j app without a php ? I always worked with php files.

( I will check the opcache for apache by the way )
 
Upvote 0
Top