taosdata/taosadapter

bug: taosadapter hang up after continuous query a simple sql

freemine opened this issue · 4 comments

TDengine commit: bca86d6936f180367da21aa44fa2d67c72b9ef2f
taosadapter commit: 54547a0
taosws-rs commit: e8b6ae4fdee1a03e9d4529f3e0079fc6827a1562

test source code: save as x.c

#include <taosws.h>
#include <stdio.h>
#include <errno.h>

static int flaw(void)                                                                                                                                                           
{                                                                                  
  const char *url = "taos://localhost:6041";                                       
                                                                                   
  WS_TAOS *taos = ws_connect_with_dsn(url);                                        
  if (!taos) {                                                                     
    fprintf(stderr, "failed to connect:%s\n", url);                                
    return -1;                                                                     
  }                                                                                
  if (!taos) return -1;                                                            
                                                                                   
  // "create database if not exists foo"                                           
  // "create table if not exists foo.t (ts timestamp, name varchar(20))"           
                                                                                   
  const char *sql = "select * from foo.t";                                         
  size_t tick = 0;                                                                 
  WS_RES *res = NULL;                                                              
  int e = 0;                                                                       
                                                                                   
again:                                                                             
                                                                                   
  ++tick;                                                                          
  fprintf(stderr, "tick: %zd: ws_query(%p, %s) ...\n", tick, taos, sql);           
  res = ws_query(taos, sql);                                                       
  fprintf(stderr, "tick: %zd: ws_query(%p, %s) => %p\n", tick, taos, sql, res); 
  e = ws_errno(res);                                                               
  if (e) {                                                                         
    fprintf(stderr, "failed executing sql:%s\n", sql);                             
  }                                                                                
  if (res) {                                                                       
    fprintf(stderr, "tick: %zd: ws_free_result(%p) ...\n", tick, res);             
    ws_free_result(res);                                                           
    fprintf(stderr, "tick: %zd: ws_free_result(%p) done\n", tick, res);            
  }                                                                                
                                                                                   
  if (e == 0) goto again;                                                          
                                                                                   
  ws_close(taos);                                                                  
  return e;                                                                        
}

int main(int argc, char *argv[])                                                
{                                                                               
  int r;                                                                        
                                                                                                                                                                                
  r = flaw();                                                                   
                                                                                
  fprintf(stderr, "==%s==\n", r ? "failure" : "success");                       
                                                                                
  return !!r;                                                                   
}                                                                                                                                                         

to reproduce:

1. gcc x.c -ltaosws
2. taos -s 'drop database if exists foo'
3. taos -s 'create database foo'
4. taos -s 'create table if not exists foo.t (ts timestamp, name varchar(20))'
5. taos -s 'select * from foo.t'
6. curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d 'select * from foo.t' localhost:6041/rest/sql
7. ./a.out
hanging up after more. than 199x iterations on my machine
8, Ctrl-C to terminate ./a.out process

to check. the state

1. taos -s 'select * from foo.t'
2. curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d 'select * from foo.t' localhost:6041/rest/sql
hanging up
3. Ctrl-C to terminate curl process

to rescue from above situation

1. taos -s 'drop database if exists foo'
2. curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" -d 'select * from foo.t' localhost:6041/rest/sql
now it's working
3. prepare database and tables as above
4. ./a.out
hanging up again

The problem has been found in libtaosws

it's been noticed that there's no request type which is related to TaosClose.
does this mean, that any single websocket connection to taosadapter, for it's whole lifetime, shall have no more than one concrete taos-connection under the hood? and this taos-connection keeps alive until the websocket disconnected.

just FYI:
when in hanging up state, open another terminal and netstat -na | grep 6030 | wc -l, it reports more than 2000 pair of established connections.

it's been noticed that there's no request type which is related to TaosClose. does this mean, that any single websocket connection to taosadapter, for it's whole lifetime, shall have no more than one concrete taos-connection under the hood? and this taos-connection keeps alive until the websocket disconnected.

just FYI: when in hanging up state, open another terminal and netstat -na | grep 6030 | wc -l, it reports more than 2000 pair of established connections.

TDengine 3.0.6.0 fixed

fixed ack. thx!