Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.IO.EndOfStreamException: Unexpected end of stream; expected type 'MultiBulk' #35

Open
kinsen opened this issue Sep 29, 2018 · 26 comments
Labels

Comments

@kinsen
Copy link

kinsen commented Sep 29, 2018

调用RedisHelper.Keys频繁抛出异常.

System.IO.EndOfStreamException: Unexpected end of stream; expected type 'MultiBulk'
   at CSRedis.Internal.IO.RedisReader.ExpectType(RedisMessage expectedType)
   at CSRedis.Internal.Commands.RedisArray.Generic`1.Parse(RedisReader reader)
   at CSRedis.Internal.RedisConnector.Call[T](RedisCommand`1 command)
   at CSRedis.RedisClient.Write[T](RedisCommand`1 command)
   at CSRedis.RedisClient.Keys(String pattern)
   at CSRedis.CSRedisClient.Keys(String pattern)
   at RedisHelper.Keys(String pattern)
   at NbCRM.Account.TokenHelper.GetXTokenFromRedis(String plainToken) in C:\Projects\NbCRM\NbCRM.Account\src\NbCRM.Account\Helper\TokenHelper.cs:line 75
   at NbCRM.Account.Impl.UserServiceImpl.GetUserPath(Querys request, ServerCallContext context) in C:\Projects\NbCRM\NbCRM.Account\src\NbCRM.Account\Impl\UserServiceImpl.cs:line 750
   at Grpc.Core.Internal.UnaryServerCallHandler`2.<>c__DisplayClass4_2.<<HandleCall>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
@2881099
Copy link
Owner

2881099 commented Sep 29, 2018

怎么重现问题。我测试没发现问题

@kinsen
Copy link
Author

kinsen commented Sep 30, 2018

这个问题很奇怪,Windows上没有出现,Linux频繁出现,目前还没发现100%复现的方式..

@2881099
Copy link
Owner

2881099 commented Sep 30, 2018

keys 查的参数是什么?
预计返回数据多少条,中间有没有特别长的keyname?
同样的参数,在redis-cli执行,是否正常?

截图多收集相关数据

@2881099
Copy link
Owner

2881099 commented Sep 30, 2018

    public void ExpectType(RedisMessage expectedType)
    {
        RedisMessage type = ReadType();
        if ((int)type == -1)
            throw new EndOfStreamException("Unexpected end of stream; expected type '" + expectedType + "'");
        if (type != expectedType)
            throw new RedisProtocolException(String.Format("Unexpected response type: {0} (expecting {1})", type, expectedType));
    }

服务端返回-1,才会出这个错误

@kinsen
Copy link
Author

kinsen commented Sep 30, 2018

不是服务端返回-1,应该是流结束了..
查询的参数 一般为 AX*这样的. 长度不超过64.
cli中查询很正常.

@2881099
Copy link
Owner

2881099 commented Sep 30, 2018

我这里没办法重现问题啊,下面的代码测试没报错。

for (var a = 0; a < 50; a++) {
	new Thread(() => {
		for (int i = 0; i < 100; i++) {
			Task.Run(async () => {
				try {
					var keysall = RedisHelper.Keys("*");
					var keys = RedisHelper.Keys("lkjsdglkjskldgk*slkdgjlksdjgkl");

					Console.WriteLine(keys.Length + "/" + keysall.Length);
				} catch (Exception ex) {
					Console.WriteLine(ex);
				}

				await Task.Delay(200);
			}).Wait();
		}
	}).Start();
}

@2881099
Copy link
Owner

2881099 commented Sep 30, 2018

你那里可以必报错误吗?

@zhyuxwz
Copy link

zhyuxwz commented Jan 10, 2019

会不会是因为redis的timeout配置的原因?我这边在将timeout配置为非0的值的时候也会遇到这样的问题

@mirbeta
Copy link

mirbeta commented Apr 11, 2019

经常遇到这个问题....不管是windows和linux下

@mirbeta
Copy link

mirbeta commented Apr 11, 2019

Unable to read data from the transport connection: 你的主机中的软件中止了一个已建立的连接。. ---> System.Net.Sockets.SocketException: 你的主机中的软件中止了一个已建立的连接。

Unexpected end of stream; expected type 'Bulk'

@2881099
Copy link
Owner

2881099 commented Apr 11, 2019

连接终止了,然后跟着读取数据不正确。

可下载源码搜索【Unexpected end of stream; expected type】,只有一个地方

@JimReal
Copy link

JimReal commented Aug 30, 2019

我也遇到同样的问题,目前可以确定的是我这边使用HGetAllAsync方法是必现的,改为HGetAll不出现此问题,或许从异步方面排查会有线索,Linux服务器、3.0.53版本

@yescent
Copy link

yescent commented Aug 30, 2019

使用 HGetAll方法时候出现,csreids 错误【10.0.0.36:6379/0】:Unexpected end of stream; expected type 'MultiBulk'; data = at CSRedis.CSRedisClient.GetAndExecute[T](RedisClientPool pool, Func`2 handler, Int32 jump, Int32 errtimes)

@2881099
Copy link
Owner

2881099 commented Aug 30, 2019

@JimReal @yescent 是必然出现的吗?增加 tryit=1 参数试试

@yescent
Copy link

yescent commented Aug 30, 2019

@JimReal @yescent 是必然出现的吗?增加 tryit=1 参数试试

增加 tryit=1 还是报错
系统为linux,timeout设置为0

@2881099
Copy link
Owner

2881099 commented Aug 30, 2019

是否开启了 ssl

@yescent
Copy link

yescent commented Aug 30, 2019

没有开启

@2881099
Copy link
Owner

2881099 commented Aug 30, 2019

使用同步方法呢?

@2881099
Copy link
Owner

2881099 commented Aug 30, 2019

是 HGetAllAsync 还是 HGetAll 出的错?

@yescent
Copy link

yescent commented Aug 30, 2019

HGetAll

@2881099
Copy link
Owner

2881099 commented Aug 30, 2019

代码发出来看下

@yescent
Copy link

yescent commented Aug 30, 2019

var csredis = new CSRedisClient(null,connectionString);
//初始化 RedisHelper
RedisHelper.Initialization(csredis);



public class RedisDb: IRedisDb
{
    public  List<T> HashGetAll<T>(string key)
    {
        List<T> list = new List<T>();
        try
        {
            return RedisHelper.HGetAll<T>(key)?.Select(x => x.Value).ToList();
        }
        catch (Exception) { }
        return list;
    }
}

@JimReal
Copy link

JimReal commented Aug 31, 2019

var res = RedisHelper.HGetAllAsync(string.Format(gxin_users_{0}, id));
id是一个guid。

@vincentelite
Copy link

is there a solution ?we run into the same Dilemma.

@JimReal
Copy link

JimReal commented Sep 18, 2019

There is nothing for the time being,you can try async or not async in two ways.

@2881099
Copy link
Owner

2881099 commented Sep 18, 2019

Did redis-server turn SSL on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants