0

I used C# TDengine driver to subscribe data from taos database. My a sample code is like bellow:

public void RunSubscribeWithoutCallback(IntPtr conn, string table)
        {

            PrepareData(conn, table);
            string topic = $"{table}_topic";
            string sql = $"select * from {table}";
            IntPtr subscribe = TDengine.Subscribe(conn, true, topic, sql, null, IntPtr.Zero, 1000);
            Console.WriteLine("consume from begin");
            IntPtr taosRes = TDengine.Consume(subscribe);

            UtilsTools.DisplayRes(taosRes);
            TDengine.FreeResult(taosRes);
            for (int i = 0; i < 3; i++)
            {
                InsertData(conn, table);
            }
            Console.WriteLine("consume new data");
            taosRes = TDengine.Consume(subscribe);
            UtilsTools.DisplayRes(taosRes);
            Console.WriteLine("Unsubscribe and keep progress");
            TDengine.FreeResult(taosRes);

            TDengine.Unsubscribe(subscribe, false);
        }

While the output is like these

root@mybook:~/git_space/test/TDengine/src/connector/C#/examples# dotnet run drop database if exists csharp_example_db success create database if not exists csharp_example_db keep 3650 success use csharp_example_db success create table if not exists subscribe_without_callback (ts timestamp,i8 tinyint,i16 smallint,i32 int,i64 bigint); success insert into subscribe_without_callback values(1646150410000,1,2,3,4) success consume from begin 1646150410000 | 1 | 2 | 3 | 4 | insert into subscribe_without_callback values(1646150410100,1,2,3,4) success insert into subscribe_without_callback values(1646150410200,-1,-2,-3,-4) success insert into subscribe_without_callback values(1646150410300,1,2,3,4) success insert into subscribe_without_callback values(1646150410400,-1,-2,-3,-4) success insert into subscribe_without_callback values(1646150410500,1,2,3,4) success insert into subscribe_without_callback values(1646150410600,-1,-2,-3,-4) success consume new data

I can only get consume the first time. For the next time the application crashed. And there isn’t any error in taoslog file. Does any one know how to fix this?

Ray Shown
  • 33
  • 6

1 Answers1

0

I also faled in this situation before. This is because you free the taosRes which is a struct TAOS_RES, there an some memory share by for the object subscribe Which is a struct TAOS_SUB. they share a pointer SSqlObj * pSql; if you release you 'taosRes' that will lead for the next consume segment fault and this is hard for C# application to realize this. What's more, this has been mentioned in TDengine's website. interface description

xiaolei
  • 43
  • 1
  • 6