rust-mysql-simple icon indicating copy to clipboard operation
rust-mysql-simple copied to clipboard

"Connection reset by peer" on certain SELECT and CALL statements

Open rideron89 opened this issue 5 years ago • 2 comments

11/03/2020 Update: I was having this problem yesterday, after a couple more run attempts it just started working. No code/server/configuration changes. Now it is back to throwing the error again.


I have a relatively complex SELECT statement (35 lines; some UNIONs in a subquery) that is hanging for about 20 seconds before the following error:

CodecError { IO error: `Connection reset by peer (os error 104)' }

Here is my truncated code:

let pool = {
    let options = OptsBuilder::new()
        .ip_or_hostname(Some(&self.config.database.host))
        .tcp_port(self.config.database.port)
        .db_name(Some(&self.config.database.db_name))
        .user(Some(&self.config.database.user))
        .pass(Some(&self.config.database.pass));

    Pool::new(options)?
};

// ...

#[derive(Clone, Debug, Serialize)]
pub struct Account {
    pub zoho_id: String,
    pub corporate_group: String,
    pub corporate_group_number: usize,
    pub total_insureds: i64,
}

impl mysql::prelude::FromRow for Account {
    fn from_row_opt(row: mysql::Row) -> Result<Self, mysql::FromRowError> {
        let zoho_id = row.get_opt(0).unwrap().map_err(|_| mysql::FromRowError(row.clone()))?;
        let corporate_group = row.get_opt(1).unwrap().map_err(|_| mysql::FromRowError(row.clone()))?;
        let corporate_group_number = row.get_opt(2).unwrap().map_err(|_| mysql::FromRowError(row.clone()))?;
        let total_insureds = row.get_opt(3).unwrap().map_err(|_| mysql::FromRowError(row.clone()))?;

        Ok(Self {
            zoho_id,
            corporate_group,
            corporate_group_number,
            total_insureds,
        })
    }
}

// ...

let sql = "CALL getAccountsChurn()";
let accounts = pool.get_conn()?.query_map(sql, |account: Account| account)?;

26 records of 4 columns are to be returned, so I don't think it is a size issue. I can run the same statement in my interactive client (HeidiSQL), the command line, and a separate PHP app just fine. The queries takes about 1-2 seconds to complete.

I moved the select statements into simple stored procedures (with just the select statement), and a couple of the queries started working, but not all of them.

When I run SHOW PROCESSLIST while it's hanging, all pooled connections are sleeping.

I'm using MariaDB 10.3.8 on Windows Server 2016. Here are my SQL timeout settings:

interactive_timeout = 28800
net_read_timeout = 28800
net_write_timeout = 28800
thread_pool_idle_timeout = 60
wait_timeout = 28800

The only MariaDB error message I get is this one at the time I receive the os error 104 in my client:

[Warning] Aborted connection 34 to db: 'db_name' user: 'root' host: '192.168.0.99' (Got an error reading communication packets)

I'm really not sure what to blame. But I figure I'll put in this report, just in case there is a weird edge bug to be found.

rideron89 avatar Nov 03 '20 14:11 rideron89

Hi. Thanks for report. Regarding your database instance - is it on local or remote host?

blackbeam avatar Nov 03 '20 14:11 blackbeam

Hello! The database is remote (and connected through a VPN). I am also using WSL 2 (Debian) locally under Windows 10.

I just compiled for Windows and it works both locally (through Windows) and remote. So it might be a WSL 2 issue.

In case this helps, here are my build targets (couldn't get windows-msvc to compile debug):

Local (WSL): x86_64-unknown-linux-gnu (debug) [broken] Local: x86_64-pc-windows-msvc (release) [works] Remote: x86_64-pc-windows-msvc (release) [works]

rideron89 avatar Nov 03 '20 14:11 rideron89