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

Contract failure in consume!string #20

Closed
simendsjo opened this issue Sep 21, 2013 · 6 comments
Closed

Contract failure in consume!string #20

simendsjo opened this issue Sep 21, 2013 · 6 comments

Comments

@simendsjo
Copy link

consume!string fails on in contract as packet.length < N
This happens when trowing in a lot of concurrent web requests.
Could the error be in vibes connection..?

[email protected](752): Assertion failure
----------------
./simendsjo-homepage(_d_assertm+0x26) [0x6e00ae]
./simendsjo-homepage() [0x6d51f5]
./simendsjo-homepage(pure nothrow immutable(char)[] mysql.connection.consume!(immutable(char)[]).consume(ref ubyte[], ulong)+0x27) [0x6cf6f7]
./simendsjo-homepage(ubyte[] mysql.connection.Connection.parseGreeting()+0x9d) [0x6c2b9d]
./simendsjo-homepage(void mysql.connection.Connection.connect(mysql.connection.SvrCapFlags)+0x91) [0x6c3789]
./simendsjo-homepage(mysql.connection.Connection mysql.connection.Connection.__ctor(mysql.connection.MySQLSocketType, std.socket.TcpSocket function(immutable(char)[], ushort)*, vibe.core.net.TCPConnection function(immutable(char)[], ushort)*, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.connection.SvrCapFlags)+0x15d) [0x6c3b3d]
./simendsjo-homepage(mysql.connection.Connection mysql.connection.Connection.__ctor(mysql.connection.MySQLSocketType, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.connection.SvrCapFlags)+0x66) [0x6c3916]
./simendsjo-homepage(mysql.connection.Connection mysql.connection.Connection.__ctor(immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.connection.SvrCapFlags)+0x50) [0x6c38a0]
./simendsjo-homepage(mysql.connection.Connection mysql.db.MysqlDB.createConnection()+0x58) [0x6bbf00]
./simendsjo-homepage(vibe.core.connectionpool.LockedConnection!(mysql.connection.Connection).LockedConnection vibe.core.connectionpool.ConnectionPool!(mysql.connection.Connection).ConnectionPool.lockConnection()+0x1dc) [0x6bc114]
./simendsjo-homepage(vibe.core.connectionpool.LockedConnection!(mysql.connection.Connection).LockedConnection mysql.db.MysqlDB.lockConnection()+0x6e) [0x6bbe8e]
./simendsjo-homepage(mysql.connection.ResultSet simendlib.mysql.query!().query(mysql.db.MysqlDB, immutable(char)[])+0x36) [0x65c78e]
./simendsjo-homepage(_D9simendlib5mysql469__T9queryExprTS4vibe5templ5utils34__T11reqInjectorS143app9pgGetUserZ11reqInjectorFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZ205__T9pgGetUserS187_D4vibe5templ5utils34__T11reqInjectorS143app9pgGetUserZ11reqInjectorFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZv3reqC4vibe4http6server17HTTPServerRequestZ9pgGetUserMFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZ12UserListItemZ9queryExprFC5mysql2db7MysqlDBZAS4vibe5templ5utils34__T11reqInjectorS143app9pgGetUserZ11reqInjectorFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZ205__T9pgGetUserS187_D4vibe5templ5utils34__T11reqInjectorS143app9pgGetUserZ11reqInjectorFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZv3reqC4vibe4http6server17HTTPServerRequestZ9pgGetUserMFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZ12UserListItem+0xe8) [0x65c630]
./simendsjo-homepage(void vibe.templ.utils.__T11reqInjectorS143app9pgGetUserZ.reqInjector(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse).void pgGetUser!(_D4vibe5templ5utils34__T11reqInjectorS143app9pgGetUserZ11reqInjectorFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZv3reqC4vibe4http6server17HTTPServerRequest).pgGetUser(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0x67) [0x5967ef]
./simendsjo-homepage(void vibe.templ.utils.__T11reqInjectorS143app9pgGetUserZ.reqInjector(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0x20) [0x596780]
./simendsjo-homepage(void std.functional.DelegateFaker!(void function(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)*).DelegateFaker.doIt(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0x68) [0x6a1b38]
./simendsjo-homepage(void vibe.http.router.URLRouter.handleRequest(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0x179) [0x63f1b1]
./simendsjo-homepage(bool vibe.http.server.handleRequest(vibe.core.stream.Stream, immutable(char)[], vibe.http.server.HTTPServerListener, ref vibe.http.server.HTTPServerSettings, ref bool)+0x1638) [0x63bb08]
./simendsjo-homepage(void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPServerListener)+0x143) [0x63a40b]
./simendsjo-homepage(void vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings, void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)).void doListen(vibe.http.server.HTTPServerSettings, vibe.http.server.HTTPServerListener, immutable(char)[]).void __lambda93(vibe.core.net.TCPConnection)+0x2c) [0x6369b4]
./simendsjo-homepage(extern (C) nothrow void vibe.core.drivers.libevent2_tcp.onConnect(int, short, void*).void ClientTask.execute()+0x2d6) [0x5cee8e]
./simendsjo-homepage(void vibe.core.core.CoreTask.run()+0xf2) [0x5dad6a]
./simendsjo-homepage(void core.thread.Fiber.run()+0x2a) [0x70df9e]
./simendsjo-homepage(fiber_entryPoint+0x61) [0x70dea9]

@s-ludwig
Copy link

I really hope that this is not an issue in TCPConnection - it would mean that the data gets corrupted internally. But as far as I can see the immediate problem is that packet.countUntil(0) on line 2301 returns -1, so either getPacket returned a buffer that is too short, or the contents of the packet are corrupted. I'd try to dump the packet at line 2300 using if (packet.countUntil(0) < 0) writefln("Invalid packet: %s", packet);

@Marenz
Copy link

Marenz commented Apr 14, 2016

I have a similar failure:

Task terminated with unhandled exception: Assertion failure
Full error: core.exception.AssertError@../../.dub/packages/mysql-native-0.1.3/source/mysql/protocol/packet_helpers.d(356): Assertion failure

@Marenz
Copy link

Marenz commented Apr 14, 2016

In my case it's this contract:

string consume(T:string)(ref ubyte[] packet, size_t N) pure
in
{
    assert(packet.length >= N);
}
body
{
    return cast(string)packet.consume(N);
}

@Marenz
Copy link

Marenz commented Apr 14, 2016

Sorry, forgot the trace:

??:? _d_assert [0xbcbec3]
??:? void mysql.protocol.packet_helpers.__assert(int) [0xa296a7]
../../.dub/packages/mysql-native-0.1.3/source/mysql/protocol/packet_helpers.d:356 pure nothrow @nogc immutable(char)[] mysql.protocol.packet_helpers.consume!(immutable(char)[]).consume(ref ubyte[], ulong) [0xa2a3ea]
../../.dub/packages/mysql-native-0.1.3/source/mysql/connection.d:282 ubyte[] mysql.connection.Connection.parseGreeting() [0xa1f981]
../../.dub/packages/mysql-native-0.1.3/source/mysql/connection.d:408 void mysql.connection.Connection.connect(mysql.protocol.constants.SvrCapFlags) [0xa2014a]
../../.dub/packages/mysql-native-0.1.3/source/mysql/connection.d:502 mysql.connection.Connection mysql.connection.Connection.__ctor(mysql.common.MySQLSocketType, std.socket.TcpSocket function(immutable(char)[], ushort)*, vibe.core.net.TCPConnection function(immutable(char)[], ushort)*, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.protocol.constants.SvrCapFlags) [0xa2049c]
../../.dub/packages/mysql-native-0.1.3/source/mysql/connection.d:470 mysql.connection.Connection mysql.connection.Connection.__ctor(mysql.common.MySQLSocketType, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.protocol.constants.SvrCapFlags) [0xa20294]
../../.dub/packages/mysql-native-0.1.3/source/mysql/connection.d:461 mysql.connection.Connection mysql.connection.Connection.__ctor(immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.protocol.constants.SvrCapFlags) [0xa20227]
../../.dub/packages/mysql-native-0.1.3/source/mysql/connection.d:540 mysql.connection.Connection mysql.connection.Connection.__ctor(immutable(char)[], mysql.protocol.constants.SvrCapFlags) [0xa205be]
source/MySqlConnectionManager.d:294 MySqlConnectionManager.MySqlConnectionManager.ScopedSqlConnection MySqlConnectionManager.MySqlConnectionManager.get() [0x915eed]
source/UserManager.d:386 ulong UserManager.UserManager.update(util.SteamID.SteamID, immutable(char)[], immutable(char)[]) [0x92139d]
source/TCPHandler.d:380 void TCPHandler.TCPHandler.handleAuthenticate(ushort, ref protocol.launcher.client.__mixin5.Authenticate, tcp.TCPContext.TCPContext) [0x91a70c]
source/TCPHandler.d:270 void TCPHandler.TCPHandler.startReading(vibe.core.net.TCPConnection, tcp.TCPContext.TCPContext, vibe.core.task.Task) [0x91a1f5]
../../.dub/packages/vibe-d-0.7.26/source/vibe/core/core.d:486 void vibe.core.core.makeTaskFuncInfo!(void delegate(vibe.core.net.TCPConnection, tcp.TCPContext.TCPContext, vibe.core.task.Task), vibe.core.net.TCPConnection, tcp.TCPContext.TCPContext, vibe.core.task.Task).makeTaskFuncInfo(ref void delegate(vibe.core.net.TCPConnection, tcp.TCPContext.TCPContext, vibe.core.task.Task), ref vibe.core.net.TCPConnection, ref tcp.TCPContext.TCPContext, ref vibe.core.task.Task).callDelegate(vibe.core.core.TaskFuncInfo*) [0x9896c3]
../../.dub/packages/vibe-d-0.7.26/source/vibe/core/core.d:1005 void vibe.core.core.CoreTask.run() [0xa5dc2f]
??:? void core.thread.Fiber.run() [0xc25a7d]
??:? fiber_entryPoint [0xc257f7]
??:? [0xffffffff]

@Marenz
Copy link

Marenz commented Apr 14, 2016

After adding your dump code, I get this:

Invalid packet: [16, 4, 84, 111, 111, 32, 109, 97, 110, 121, 32, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 115]

@Marenz
Copy link

Marenz commented Apr 14, 2016

Turns out this was an error packet "too many connections" which the client didn't check for. See PR for fix.

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

No branches or pull requests

3 participants