RE: [Quickfix-users] Possible bug in the Parser when receiving hu ge amounts through th e socket
Brought to you by:
orenmnero
From: <em...@co...> - 2004-12-13 12:02:23
|
I am not quite suire of the version I am using but this is the code that was giving me trouble. I am not sure of the version becase I have customised the code heavily, so I have lately taken code from your updated versions and big fixes and just added, instead of taking a whole new release, sorry about this ;)... The following was giving me trouble. I think the problem is that the 'extractLength' below should not be called before 'pos = m_buffer.find( "\00110=", pos-1 );', this is because you cannot check for the length unless the 'standard trailer' is part of the message. This is the problem I was faced with where the only thing I would have in the buffer when trying to extract the length is '8=FI', and obviously at this point the extractLength would throw an exception. So, I have just modified it to check for the standard message trailer before attempting to extract length and have not seen this problem. Here is the code below. bool Parser::readFixMessage( std::string& str ) throw( MessageParseError&, RecvFailed& ) { QF_STACK_PUSH(Parser::readFixMessage) readFromStream(); std::string::size_type pos = 0; if( m_buffer.length() < 2 ) return false; pos = m_buffer.find( "8=" ); if( pos == std::string::npos ) return false; int pos_end_trailer_ = m_buffer.find( "\00110="); \\ I HAVE ADDED THE FOLLOWING 3 LINES if(pos_end_trailer_ == std::string::npos) \\ AND HAVE SEEMED TO SOLVED THE PRBLEM return false; \\ if(pos) m_buffer.erase( 0, pos ); int length = 0; try { if( extractLength(length, pos, m_buffer) ) { pos += length; if( m_buffer.size() < pos ) return false; pos = m_buffer.find( "\00110=", pos-1 ); if( pos == std::string::npos ) return false; pos += 4; pos = m_buffer.find( "\001", pos ); if( pos == std::string::npos ) return false; pos += 1; str = m_buffer.substr( 0, pos ); m_buffer.erase( 0, pos ); return true; } } catch( MessageParseError& e ) { m_buffer.erase( 0, pos + length ); throw e; } readFromStream(); return false; QF_STACK_POP } I hope this helps. Regards, Emir -----Original Message----- From: Oren Miller [mailto:or...@qu...] Sent: Friday, December 10, 2004 10:04 PM To: em...@co...; qui...@li... Subject: Re: [Quickfix-users] Possible bug in the Parser when receiving huge amounts through th e socket QuickFIX Documentation: http://www.quickfixengine.org/quickfix/doc/html/index.html QuickFIX FAQ: http://www.quickfixengine.org/wikifix/index.php?QuickFixFAQ QuickFIX Support: http://www.quickfixengine.org/services.html I think I do need some more information about the version you are using. I wrote a test and ran it against 1.9.4 and was not able to duplicate the behavior described. The parser has changed over time so it may have been resolved somewhere along the way. What version are you using? --oren ----- Original Message ----- From: <em...@co...> To: <qui...@li...> Sent: Thursday, December 09, 2004 10:14 AM Subject: [Quickfix-users] Possible bug in the Parser when receiving huge amounts through th e socket > QuickFIX Documentation: > http://www.quickfixengine.org/quickfix/doc/html/index.html > QuickFIX FAQ: http://www.quickfixengine.org/wikifix/index.php?QuickFixFAQ > QuickFIX Support: http://www.quickfixengine.org/services.html > > Here is the scenario. > > At the moment the socket buffer in the parser is 4096. So, I have recently > generated a lot of traffic so I constantly receive of 4096 bytes on the > socket and have encountered the following problem. > > The end of the incoming buffer (m_buffer) of 4096 is as follows (some of > the > values have been substituted to hide trading details): > > 8=FIX.4.29=29135=834=156110369=3145052=20041209-15:35:32.68749=BLA50= > G56=D33030N60=20041209-15:35:3259=055=GE54=148=BLA000060467107=BLF51 > 67=FUT44=9740.0041=040=239=038=1037=20041209004077151=10150=020=09 > 717=6796017=0068712004120909353214=011=000679606=0432=200412091=123456 > 7810=0978=F > > As we can see, when the parser gets to parsing this part of the buffer, it > will extract the length of the valid message which is 294 (9=291) and in > turn send of the message for processing into the application code, etc. > After, it has processed the message the buffer then looks like: > > 8=F > > This is because the rest of the message is resting on the socket to be > read > so a valid FIX message can be composed. > > As you can see there is a 8=F at the end which was received into the > buffer, > and more data is left over on the socket to be read into the buffer. But, > at > the moment what the parser will do is make 8=F into a fix message as this > is > where the buffer is ending, and will try and extract length from it, and > this generates a series of exceptions (FieldConvertError, > MessageParseError, > FieldNotFound and InvalidMessage). > > > Once the parser tries to parse this message, and throws its exceptions, it > will get around to reading the socket again and receiving the following > into > buffer: > > IX.4.29=34935=834=156111369=3145052=20041209-15:35:32.69249=BLA50=G5 > 6=D33030N60=20041209-15:35:3259=055=GE54=148=CME000060467107=BLF5167= > FUT44=9740.0041=040=239=238=1037=20041209004077337=0C032=1031=9740. > 00151=0150=220=09717=6796017=00687220041209093532TN000284375=20041209 > 14=011=00067960375=BLA030A16=0432=200412091=1234567810=178 > > Once this is received the m_buffer is "8=F" and m_readBuffer is as above. > When the parser appends m_readBuffer to m_buffer the message looks like: > > 8=FIX.4.29=34935=834=156111369=3145052=20041209-15:35:32.69249=BLA50= > G56=D33030N60=20041209-15:35:3259=055=GE54=148=CME000060467107=BLF51 > 67=FUT44=9740.0041=040=239=238=1037=20041209004077337=0C032=1031=97 > 40.00151=0150=220=09717=6796017=00687220041209093532TN000284375=200412 > 0914=011=00067960375=BLA030A16=0432=200412091=1234567810=178 > > a COMPLETE message as it should be. > > Now surely, if this kind of scenario is encountered the parser should not > even attempt to parse the message, as it is incomplete. I think that there > needs to be an extra safeguard in the parser that needs to check presence > of > field 10 (Standard Trailer) in order to verify that it is a complete > message. > > If anyone has any ideas how to solve this, please be my guess as it has > taken my over 2 days just to track this problem down. > > Thanks a lot > > Emir > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004 > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Quickfix-users mailing list > Qui...@li... > https://lists.sourceforge.net/lists/listinfo/quickfix-users > ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/ _______________________________________________ Quickfix-users mailing list Qui...@li... https://lists.sourceforge.net/lists/listinfo/quickfix-users --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.766 / Virus Database: 513 - Release Date: 9/17/2004 |