Read failed error code read time out

FTP 'Read Timed out' error can happen due to server firewall settings, ftp client settings, etc. Here are the 4 reasons for this error and how to fix them.

Nothing can be as annoying as getting timeout error when accessing an application.

One such error is FTP “Read timed out“. You are waiting for a successful FTP connection, but at the end it throws a timeout error.

Quite frustrating right? And, you know that the connection timed out, but where?

At Bobcares, we help website owners resolve these errors as part of our Dedicated Support Services for web hosts.

Today, we’ll discuss the top 4 reasons for ftp read timed out error and how we fix them.

What is FTP ‘Read Timed out’ error?

FTP Read Timed out error means that the client or server couldn’t read data from the source and has given up waiting for the information requested.

Users see the complete error message like this:

Failed to upload file
Establishing FTP connection failed: Read timed out
Read timed out

A Read timeout error explains a little about the error and the reason for the error, it just identifies that an error has occurred. So our Hosting Engineers analyze the FTP logs(/var/log/messages) to identify the origin of the issue.

FTP ‘Read Timed out’ error – Causes and Solutions

Let’s now see the main reasons for FTP read timed out error and how our Server Support Engineers fix them.

1) Firewall blocking Passive ports in server

The standard FTP ports are 20 and 21, and these ports should be opened in the server for proper functioning of FTP.

In addition to that, the FTP server should accept connections to Passive FTP ports which vary from server to server.

But, the problem is that most servers accept connections only on standard ports. And, if it’s not specifically set to access connections on Passive FTP ports, the incoming connections fail.

Consequently, users see FTP Read Timed out error.

Solution

Firstly, our Hosting Engineers confirm that the connectivity to the standard FTP ports 20 and 21 works well using the below command.

telnet hostname 20
telnet hostname 21

Secondly, we verify that the Passive port range is specified in the FTP configuration file.

For example, in a ProFTPd server, we un-comment the following directive in the configuration file /etc/proftpd.conf to specify the Passive port range.

PassivePorts 49152 65535

Finally, we open these passive port range in the server firewall.

For example, in a Linux server, we open the passive port range in firewall using the below command.

iptables -A INPUT -p tcp --match multiport --dports xxxxx:yyyyy -j ACCEPT

Here, xxxxx is the starting port, and yyyyy is the ending port in the Passive port range.

[Do you need help enabling Passive ports on your server? One of our Sever Experts can enable it for you in minutes.]

2) FTP client set to use Active mode

Another common reason for this error is that users enable Active mode in FTP client to transfer the files.

FTP transfers can happen in Passive and Active modes. However, active mode requires users to configure their PCs to connect to standard ports from the server.

In Active mode, the FTP client doesn’t make the actual connection to the server. Instead, it tells the server on which port it listens, and the server connects back to the specified port.

But this connection appears to be a cyber attack from the client side firewall, and hence it blocks such non-standard connections.

We’ve seen cases in which users have accidentally set their FTP mode to Active, resulting in FTP Read Timed out errors.

Solution

The solution here differs based on the FTP client software used by the users.

So, our Hosting Engineers first get the FTP client details used by the customer. And, we help users navigate their FTP client settings and enable Passive mode.

We always recommend users to enable Passive mode as the default option in their FTP clients.

[Not sure about the FTP settings to be used for your account? One of our Support Experts can help you here.]

3) Increase connection timeout limit

Usually, FTP Read Timed out error can occur when users try to upload a relatively large file. And, this problem is related to the internal timeout settings of the FTP client.

In other words, when users upload a large file, then the upload process may fail if it’s not completed within that predefined connection timeout limit.

Solution

In such cases, our Support Engineers help users to increase the Timeout values in their FTP clients accordingly.

Alternatively in some cases, we completely disable the Timeout value by setting it’s value as 0.

4) Intermediate firewall or routers block Passive ports

The majority of users are unaware of the firewall between their PC and server. This can be your network administrator or ISPs setting up a third-party firewall, intermediate firewall or a firewall on a router.

We’ve seen routers, proxies, etc. block connections through passive ports.

Solution

To resolve this, we ask users to turn off their gateways or routers to establish a direct connection. This helps us to determine if the block exists at the intermediate end.

Once, we’ve confirmed that the problem is with the intermediate devices, users can work with their network administrator or ISPs to set up the intermediate firewall to allow connections to passive ports.

Conclusion

In short, FTP Read Timed out error can happen due to server firewall settings, ftp client settings, and more. Today we’ve discussed the top 4 reasons of this error and how our Dedicated Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Hi, thanks for your reply, yes the callbacks are implemented and they work in fact the message «read failed, socket might closed or timeout, read ret: -1» its coming from @OverRide public void onConnectError(BluetoothDevice device, String message), this is the code:

package com.example.aleal.app_bt_1;

import android.Manifest;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import me.aflak.bluetooth.Bluetooth;
import me.aflak.bluetooth.BluetoothCallback;
import me.aflak.bluetooth.DeviceCallback;
import me.aflak.bluetooth.DiscoveryCallback;

import static java.security.AccessController.getContext;

public class MainActivity extends AppCompatActivity {

Bluetooth bluetooth = new Bluetooth(this);
private ListView lv;
ArrayList<String> devices_list = new ArrayList<>();
String name;
BluetoothDevice device_dongle;
String mensaje;
int MY_PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION=1;

@Override
protected void onStart() {
    super.onStart();
    bluetooth.onStart();
}

@Override
protected void onStop() {
    super.onStop();
    bluetooth.onStop();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView lv1 = (ListView)findViewById(R.id.element_list);
    bluetooth.setBluetoothCallback(new BluetoothCallback() {
        @Override
        public void onBluetoothTurningOn() {


        }

        @Override
        public void onBluetoothOn() {

        }

        @Override
        public void onBluetoothTurningOff() {


        }

        @Override
        public void onBluetoothOff() {

        }

        @Override
        public void onUserDeniedActivation() {
            bluetooth.showEnableDialog(MainActivity.this);
            bluetooth.onActivityResult(1,1);
            // when using bluetooth.showEnableDialog()
            // you will also have to call bluetooth.onActivityResult()
        }
    });

    bluetooth.setDiscoveryCallback(new DiscoveryCallback() {

        @Override
        public void onDiscoveryStarted() {
            // scan finished

        }

        @Override
        public void onDiscoveryFinished() {
            // scan finished

        }

        @Override
        public void onDeviceFound(BluetoothDevice device) {
            // device found
            lv = (ListView) findViewById(R.id.element_list);
            devices_list.add(device.getName() + "n" + device.getAddress());
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1,devices_list);
            lv.setAdapter(arrayAdapter);
            name= device.getName().toString();
            if(name.equals("BLE-SPP"))
            {
                device_dongle=device;
            }

        }

        @Override
        public void onDevicePaired(BluetoothDevice device) {
            // device paired
            device_dongle=device;
        }

        @Override
        public void onDeviceUnpaired(BluetoothDevice device) {
            // device unpaired
        }

        @Override
        public void onError(String message) {
            // error occurred
        }
    });

    bluetooth.setDeviceCallback(new DeviceCallback() {
        @Override public void onDeviceConnected(BluetoothDevice device)
        {
            device_dongle=device;
        }
        @Override public void onDeviceDisconnected(BluetoothDevice device, String message)
        {


        }
        @Override public void onMessage(String message)
        {

        }
        @Override public void onError(String message)
        {

            mensaje=message;

        }
        @Override public void onConnectError(BluetoothDevice device, String message)
        {

            device_dongle=device;
        }
    });

  lv1.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            if(bluetooth.isEnabled())
            {
                if (!bluetooth.isConnected())
                {
                    bluetooth.stopScanning();
                    name = ((TextView) view).getText().toString();
                    CharSequence dev = name;
                    int endIndex = name.lastIndexOf("n");
                    bluetooth.pair(device_dongle);
                }
            }
        }
    });

}

public void eneable_BT(View view) {
    // Do something in response to button click
    if(!bluetooth.isEnabled())
        bluetooth.enable();
    else {
    //    Toast.makeText(this, "EL Bluetooth ya esta encendido!",
    //            Toast.LENGTH_LONG).show();
    }
}

public void find_list(View view) {
    // Do something in response to button click
    if(bluetooth.isEnabled())
    ActivityCompat.requestPermissions(this,
            new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
            MY_PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION);
        bluetooth.startScanning();
}

public void disconnect(View view) {
    // Do something in response to button click
    if(bluetooth.isEnabled())
        bluetooth.disable();
    else {
     //   Toast.makeText(this, "EL Bluetooth ya esta deshabilitado!",
     //           Toast.LENGTH_LONG).show();
    }
}

public void open_drawer_1(View view) {
    // Do something in response to button click
    if (!bluetooth.isConnected())
    {
        bluetooth.connectToDevice(device_dongle);
    //    bluetooth.send("A");
    }
}

public void open_drawer_2(View view) {
    // Do something in response to button click
    if (!bluetooth.isConnected())
    {
        bluetooth.connectToDevice(device_dongle);
     //   bluetooth.send("B");
    }
}

}

this is the logcat

03-13 08:47:54.853 20238-20238/com.example.aleal.app_bt_1 D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-13 08:47:54.913 20238-20238/com.example.aleal.app_bt_1 D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-13 08:47:54.983 20238-20238/com.example.aleal.app_bt_1 D/BluetoothAdapter: cancelDiscovery
03-13 08:47:54.983 20238-20238/com.example.aleal.app_bt_1 D/BluetoothAdapter: cancelDiscovery = true
03-13 08:47:55.003 20238-20238/com.example.aleal.app_bt_1 D/BLE: PAIR RECEIVER
03-13 08:47:55.913 20238-20238/com.example.aleal.app_bt_1 D/BLE: PAIR RECEIVER
03-13 08:48:05.763 20238-20238/com.example.aleal.app_bt_1 D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-13 08:48:05.843 20238-20238/com.example.aleal.app_bt_1 D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-13 08:48:05.913 20238-20308/com.example.aleal.app_bt_1 D/BluetoothAdapter: cancelDiscovery
03-13 08:48:05.923 20238-20308/com.example.aleal.app_bt_1 D/BluetoothAdapter: cancelDiscovery = true
03-13 08:48:05.923 20238-20308/com.example.aleal.app_bt_1 D/BluetoothUtils: isSocketAllowedBySecurityPolicy start : device null
03-13 08:48:05.923 20238-20308/com.example.aleal.app_bt_1 D/BluetoothSocket: connect(): myUserId = 0
03-13 08:48:05.923 20238-20308/com.example.aleal.app_bt_1 W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback

This troubleshooting article describes what to do when Nodetool fails with a ‘Read timed out’ error.

Problem¶

When running any Nodetool command, users may see the following error:

Failed to connect to '127.0.0.1:7199' - SocketTimeoutException: 'Read timed out'

Analysis¶

Nodetool is a Java based application which requires memory. Scylla by default consumes 93% of the node’s RAM (for MemTables + Cache) and leaves 7% for other applications, such as nodetool.

If cases where this is not enough memory (e.g. small instances with ~64GB RAM or lower), Nodetool may not be able to run due to insufficient memory. In this case an out of memory (OOM) error may appear and scylla-jmx will not run.

Example¶

The error you will see is similar to:

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000,
671088640, 0) failed; error='Cannot allocate memory' (err no=12)

In order to check if the issue is scylla-jmx, use the following command (systemd-based Linux distribution) to check the status of the service:

sudo systemctl status scylla-jmx

If the service is running you will see something similar to:

sudo service scylla-jmx status
● scylla-jmx.service - Scylla JMX
   Loaded: loaded (/lib/systemd/system/scylla-jmx.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-07-18 20:59:08 UTC; 3s ago
 Main PID: 256050 (scylla-jmx)
    Tasks: 27
   Memory: 119.5M
      CPU: 1.959s
   CGroup: /system.slice/scylla-jmx.service
           └─256050 /usr/lib/scylla/jmx/symlinks/scylla-jmx -Xmx384m -XX:+UseSerialGC -Dcom.sun.management.jmxremote.auth

If it isn’t, you will see an error similar to:

sudo systemctl status scylla-jmx
● scylla-jmx.service - Scylla JMX
  Loaded: loaded (/usr/lib/systemd/system/scylla-jmx.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Thu 2018-05-10 10:34:15 EDT; 3min 47s ago
  Process: 1417 ExecStart=/usr/lib/scylla/jmx/scylla-jmx $SCYLLA_JMX_PORT $SCYLLA_API_PORT $SCYLLA_API_ADDR $SCYLLA_JMX_ADDR
  $SCYLLA_JMX_FILE $SCYLLA_JMX_LOCAL $SCYLLA_JMX_REMOTE $SCYLLA_JMX_DEBUG (code=exited, status=127)
  Main PID: 1417 (code=exited, status=127)

or

sudo service scylla-jmx status
● scylla-jmx.service
  Loaded: not-found (Reason: No such file or directory)
  Active: failed (Result: exit-code) since Wed 2018-07-18 20:38:58 UTC; 12min ago
  Main PID: 141256 (code=exited, status=143)

You will need to restart the service or change the RAM allocation as per the Solution below.

Solution¶

There are two ways to fix this problem, one is faster but may not permanently fix the issue and the other solution is more robust.

The immediate solution

service scylla-jmx restart

Note

This is not a permanent fix as the problem might manifest again at a later time.

The more robust solution

  1. Take the size of your node’s RAM, calculate 7% of that size, increase it by another 40%, and use this new size as your RAM requirement.

    For example: on a GCP n1-highmem-8 instance (52GB RAM)

    • 7% would be ~3.6GB.

    • Increasing it by ~40% means you need to increase your RAM ~5GB.

  2. Open one of the following files (as per your OS platform):

    • Ubuntu: /etc/default/scylla-server.

    • Red Hat/ CentOS: /etc/sysconfig/scylla-server

  3. In the file you are editing, add to the SCYLLA_ARGS statement --reserve-memory 5G (the amount you calculated above). Save and exit.

  4. Restart Scylla server

sudo systemctl restart scylla-server

Note

If the initial calculation and reserve memory is not enough and problem persists and/or reappears, repeat the procedure from step 2 and increase the RAM in 1GB increments.

1. Purpose

In this post, I would demonstrate how to debug the following error when using feign.

2022-02-18 15:29:38.417 ERROR 44793 --- [nio-8086-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.RetryableException: Read timed out executing GET http://nacos-provider-bswencw1/hello] with root cause

java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_121]
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_121]
        at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_121]
        at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_121]
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_121]
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[na:1.8.0_121]
        at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[na:1.8.0_121]
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704) ~[na:1.8.0_121]
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647) ~[na:1.8.0_121]
        at 

2. The solution

2.1 The details of the problem

➜  nacos-feign ./start.sh 8086
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building nacos-feign 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ nacos-feign ---
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.1.18.RELEASE:run (default-cli) > test-compile @ nacos-feign >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ nacos-feign ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ nacos-feign ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /Users/bswencaiwen/JavaProjects/SpringCloudLearning202202/nacos-feign/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ nacos-feign ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/bswencaiwen/JavaProjects/SpringCloudLearning202202/nacos-feign/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ nacos-feign ---
[INFO] Changes detected - recompiling the module!
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.1.18.RELEASE:run (default-cli) < test-compile @ nacos-feign <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.18.RELEASE:run (default-cli) @ nacos-feign ---

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.1.18.RELEASE)

2022-02-18 15:28:49.521  INFO 44793 --- [           main] c.e.nacosfeign.NacosFeignApplication     : No active profile set, falling back to default profiles: default
2022-02-18 15:28:52.439  INFO 44793 --- [           main] c.e.nacosfeign.NacosFeignApplication     : Started NacosFeignApplication in 5.934 seconds (JVM running for 10.224)
2022-02-18 15:29:38.417 ERROR 44793 --- [nio-8086-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.RetryableException: Read timed out executing GET http://nacos-provider-bswencw1/hello] with root cause

java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_121]
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_121]
        at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_121]
        at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_121]
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_121]
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[na:1.8.0_121]
        at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[na:1.8.0_121]
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704) ~[na:1.8.0_121]
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647) ~[na:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569) ~[na:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474) ~[na:1.8.0_121]
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[na:1.8.0_121]
        at feign.Client$Default.convertResponse(Client.java:82) ~[feign-core-10.4.0.jar:na]
        at feign.Client$Default.execute(Client.java:78) ~[feign-core-10.4.0.jar:na]
        at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:93) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at org.springframework.cloud.openfeign.ribbon.FeignLoadBalancer.execute(FeignLoadBalancer.java:56) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at com.netflix.client.AbstractLoadBalancerAwareClient$1.call(AbstractLoadBalancerAwareClient.java:104) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:303) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:287) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:231) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$3.call(ScalarSynchronousObservable.java:228) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.drain(OnSubscribeConcatMap.java:286) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeConcatMap$ConcatMapSubscriber.onNext(OnSubscribeConcatMap.java:144) ~[rxjava-1.3.8.jar:1.3.8]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:185) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber$1.call(OperatorRetryWithPredicate.java:127) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.enqueue(TrampolineScheduler.java:73) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.schedulers.TrampolineScheduler$InnerCurrentThreadScheduler.schedule(TrampolineScheduler.java:52) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:79) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OperatorRetryWithPredicate$SourceSubscriber.onNext(OperatorRetryWithPredicate.java:45) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Subscriber.setProducer(Subscriber.java:209) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Observable.subscribe(Observable.java:10423) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.Observable.subscribe(Observable.java:10390) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443) ~[rxjava-1.3.8.jar:1.3.8]
        at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[rxjava-1.3.8.jar:1.3.8]
        at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:112) ~[ribbon-loadbalancer-2.3.0.jar:2.3.0]
        at org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient.execute(LoadBalancerFeignClient.java:83) ~[spring-cloud-openfeign-core-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:110) ~[feign-core-10.4.0.jar:na]
        at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:80) ~[feign-core-10.4.0.jar:na]
        at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103) ~[feign-core-10.4.0.jar:na]
        at com.sun.proxy.$Proxy98.hello(Unknown Source) ~[na:na]
        at com.example.nacosfeign.clients.DemoController.hello(DemoController.java:19) ~[classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.39.jar:4.0.FR]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.39.jar:4.0.FR]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.1.19.RELEASE.jar:5.1.19.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.39.jar:9.0.39]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]

2.2 The debug process

We know that spring boot use feign(ribbon) to access remote services registered in a service registry.

But if some errors occur, how to debug this process?

2.3 The solution

We can create a config class to configure feign:

import feign.Logger;
import org.springframework.context.annotation.Bean;

public class FeignConfig {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }
}

Notice the Logger is instance of the class feign.Logger. There are 4 levels :

  • NONE, No logging (DEFAULT).
  • BASIC, Log only the request method and URL and the response status code and execution time.
  • HEADERS, Log the basic information along with request and response headers.
  • FULL, Log the headers, body, and metadata for both requests and responses.

If you want to show the request URL(including host of the URL) , you can use BASIC:

import feign.Logger;
import org.springframework.context.annotation.Bean;

public class FeignConfig {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.BASIC;
    }
}

Then we can configure FeignClient to use the config:

import com.example.nacosfeign.config.FeignConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Map;

@FeignClient(name="nacos-provider-bswencw1", configuration = FeignConfig.class)
public interface DemoClient {
    @GetMapping("hello")
    Map<String, Object> hello();
}

At last, we should change our app logging level to DEBUG to show the logs:

Say our app’s package is prefixed by com.example:

server:
  port: 8086
spring:
  application:
    name: nacos-feign
  cloud:
    nacos:
      discovery:
        server-addr: 10.1.1.1:8848
logging:
  level:
    root: ERROR
    org.springframework.web: ERROR
    com.example: DEBUG

Then run the test again, we got this debug info:

2022-02-18 15:35:45.000  INFO 45588 --- [           main] c.e.nacosfeign.NacosFeignApplication     : No active profile set, falling back to default profiles: default
2022-02-18 15:35:47.732  INFO 45588 --- [           main] c.e.nacosfeign.NacosFeignApplication     : Started NacosFeignApplication in 4.065 seconds (JVM running for 8.322)
2022-02-18 15:36:16.404 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] ---> GET http://nacos-provider-/hello HTTP/1.1
2022-02-18 15:36:16.405 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] Content-Length: 2
2022-02-18 15:36:16.405 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] Content-Type: text/plain;charset=UTF-8
2022-02-18 15:36:16.405 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] 
2022-02-18 15:36:16.405 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] aa
2022-02-18 15:36:16.405 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] ---> END HTTP (2-byte body)
2022-02-18 15:36:19.253 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] <--- ERROR SocketTimeoutException: Read timed out (2847ms)
2022-02-18 15:36:19.254 DEBUG 45588 --- [nio-8086-exec-1] c.example.nacosfeign.clients.DemoClient  : [DemoClient#hello] java.net.SocketTimeoutException: Read timed out

It works!

3. Summary

In this post, I demonstrated how to debug the application that is using feign to access remote servcies, the key point is to change the logging level of feign using spring configuration class . That’s it, thanks for your reading.

Понравилась статья? Поделить с друзьями:
  • Read failed error code connection closed by peer
  • Read error retry rate
  • Read error resource temporarily unavailable
  • Read error rate parameter goes down
  • Read error rate changed что это