bugGNUstep - Bugs: bug #42781, In the case of HTTPS...

Group
 
 

bug #42781: In the case of HTTPS NSURLConnection doesn't report to it's delegate about a refused connection

Submitter:  Sergei Golovin <svg>
Submitted:  Wed 16 Jul 2014 06:25:40 AM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 28 Jul 2014 10:45:11 AM UTC, comment #4: 

Yes, it now works. Thank you.

Sergei Golovin <svg>
Mon 28 Jul 2014 09:37:52 AM UTC, comment #3: 

I can't reproduce the problem but my best guess is that somehow ostream is being released, without clearing the ivar, before we can handle the event.
If that's happening as a result of the event sent to istream immediately before, then retaining ostream before sending the event might be sufficient to prevent the crash.
I added such a hack ... please see if it solves the problem.
If not, could you perhaps produce a testcase I can run under debug to try to track down exactly what sequence of events is causing thew problem.

Richard Frith-Macdonald <CaS>
Group Member
Sun 27 Jul 2014 12:05:13 PM UTC, comment #2: 

Instead of hanging it has began to segfault with my code.

I have a class which is used as a container for all data needed
to make a request to customer's service. The idea is to create
that class's instances with all parameters are filled and
to call the instance's methods -[start:] and -[stop] with
the runloop between. The instance makes the custom request
(from provided data), the NSURLConnection and assigns itself
as a delegate.

I have the test checking how that class behaves when
the customer's service is dead (not-listening).

The test's code chunk is:
-----------------------------------------------------------
// connect to nowhere
url = [NSURL URLWithString: @"https://localhost:30011"];
cmnd = [[testedClass alloc] initWithGateway: nil
                                        URL: url
                                    factory: nil
                                     object: nil
                                       type: C0INFO
                                 parameters: nil];
[cmnd start: nil];
while(![cmnd isCompleted])
  {
    [[NSRunLoop currentRunLoop]
       runUntilDate: [NSDate dateWithTimeIntervalSinceNow: timing]];
  }
err = [cmnd error];
-----------------------------------------------------------


The segmentation fault occurs within the runloop and here is
the gdb session:
-----------------------------------------------------------
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6cd973f in objc_msg_lookup () from /usr/lib/x86_64-linux-gnu/libobjc.so.4
(gdb) bt
#0  0x00007ffff6cd973f in objc_msg_lookup () from /usr/lib/x86_64-linux-gnu/libobjc.so.4
#1  0x00007ffff706a0c7 in -[GSTLSHandler stream:handleEvent:] (self=0x76f5a0, _cmd=0x7ffff75dada0 <_OBJC_SELECTOR_TABLE+576>,
    stream=0xc22c10, event=8) at GSSocketStream.m:660
#2  0x00007ffff7070964 in -[GSStream(Private) _sendEvent:] (self=0xc22c10, _cmd=0x7ffff75d82b0 <_OBJC_SELECTOR_TABLE+688>, event=8)
    at GSStream.m:508
#3  0x00007ffff706c871 in -[GSSocketStream _sendEvent:] (self=0xc22c10, _cmd=0x7ffff75d82b0 <_OBJC_SELECTOR_TABLE+688>, event=8)
    at GSSocketStream.m:1451
#4  0x00007ffff706da45 in -[GSSocketInputStream _dispatch] (self=0xc22a10, _cmd=0x7ffff75dac70 <_OBJC_SELECTOR_TABLE+272>)
    at GSSocketStream.m:1993
#5  0x00007ffff706fe50 in -[GSStream receivedEvent:type:extra:forMode:] (self=0xc22a10,
    _cmd=0x7ffff76c5ed0 <_OBJC_SELECTOR_TABLE+304>, data=0x7, type=ET_WDESC, extra=0x7, mode=0x7ffff765b920 <_OBJC_INSTANCE_2>)
    at GSStream.m:221
#6  0x00007ffff7283efb in -[GSRunLoopCtxt pollUntil:within:] (self=0x6f6850, _cmd=0x7ffff765cb40 <_OBJC_SELECTOR_TABLE+1216>,
    milliseconds=79, contexts=0x6f1150) at GSRunLoopCtxt.m:601
#7  0x00007ffff71b3362 in -[NSRunLoop acceptInputForMode:beforeDate:] (self=0x6f0210,
    _cmd=0x7ffff765cb80 <_OBJC_SELECTOR_TABLE+1280>, mode=0x7ffff765b920 <_OBJC_INSTANCE_2>, limit_date=0x708b50) at NSRunLoop.m:1217
#8  0x00007ffff71b378a in -[NSRunLoop runMode:beforeDate:] (self=0x6f0210, _cmd=0x7ffff765cba0 <_OBJC_SELECTOR_TABLE+1312>,
    mode=0x7ffff765b920 <_OBJC_INSTANCE_2>, date=0xc21880) at NSRunLoop.m:1288
#9  0x00007ffff71b3924 in -[NSRunLoop runUntilDate:] (self=0x6f0210, _cmd=0x6067f0 <_OBJC_SELECTOR_TABLE+176>, date=0xc21880)
    at NSRunLoop.m:1319
#10 0x0000000000403bd5 in -[PatternCommand2 startTest:] (self=0x647f60, _cmd=0x606b20 <_OBJC_SELECTOR_TABLE+160>, args=0x6d8830)
    at patternCommand2.m:351
#11 0x0000000000404005 in main (argc=1, argv=0x7fffffffd4c8, env=0x7fffffffd4d8) at testNetworkCommand2.m:42
(gdb) up
#1  0x00007ffff706a0c7 in -[GSTLSHandler stream:handleEvent:] (self=0x76f5a0, _cmd=0x7ffff75dada0 <_OBJC_SELECTOR_TABLE+576>,
    stream=0xc22c10, event=8) at GSSocketStream.m:660
660               if ([ostream streamStatus] == NSStreamStatusOpen)
(gdb) up
#2  0x00007ffff7070964 in -[GSStream(Private) _sendEvent:] (self=0xc22c10, _cmd=0x7ffff75d82b0 <_OBJC_SELECTOR_TABLE+688>, event=8)
    at GSStream.m:508
508                         handleEvent: NSStreamEventErrorOccurred];
(gdb) l
503             {
504               _events |= NSStreamEventErrorOccurred;
505               if (_delegateValid == YES)
506                 {
507                   [_delegate stream: self
508                         handleEvent: NSStreamEventErrorOccurred];
509                 }
510             }
511         }
512       else if (event == NSStreamEventEndEncountered)
(gdb) p _delegate
$4 = (struct objc_object *) 0x0
(gdb)) up
#3  0x00007ffff706c871 in -[GSSocketStream _sendEvent:] (self=0xc22c10, _cmd=0x7ffff75d82b0 <_OBJC_SELECTOR_TABLE+688>, event=8)
    at GSSocketStream.m:1451
1451          [super _sendEvent: event];
(gdb)  l
1446          id        del = _delegate;
1447          BOOL      val = _delegateValid;
1448
1449          _delegate = _handler;
1450          _delegateValid = YES;
1451          [super _sendEvent: event];
1452          _delegate = del;
1453          _delegateValid = val;
1454        }
1455      else
(gdb)  p _handler
$5 = (struct objc_object *) 0x0
(gdb)
.....
-----------------------------------------------------------



Somehow the _handler has been released during the call [super _sendEvent: event].
If i step up to the my code's frame:
-----------------------------------------------------------
.....
(gdb) up
#10 0x0000000000403bd5 in -[PatternCommand2 startTest:] (self=0x647f60, _cmd=0x606b20 <_OBJC_SELECTOR_TABLE+160>, args=0x6d8830)
    at patternCommand2.m:351
351                       [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: timing]];
(gdb) l
346                                                          type: C0INFO
347                                                    parameters: nil];
348                   [cmnd start: nil];
349                   while(![cmnd isCompleted])
350                     {
351                       [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: timing]];
352                     }
353                   err = [cmnd error];
354                   d = [[err userInfo] objectForKey: @"description"];
355                   if(nil != err &&
(gdb) ) po [[cmnd error] userInfo]
{description = "Connection refused"; source = "<C0NetworkCommand: 0xc476e0 info>"; }
(gdb)
-----------------------------------------------------------

As you see my class's instance has already got the backcall -[connection:didFailWithError:]
and stored the error from the NSURLConnection.



Sergei Golovin <svg>
Fri 25 Jul 2014 12:01:32 PM UTC, comment #1: 

Thanks ... that should be fixed in svn trunk.
Please give it a try.

PS.  Thanks very much for the testcase ... that was very useful and I added it to svn.

Richard Frith-Macdonald <CaS>
Group Member
Wed 16 Jul 2014 06:25:40 AM UTC, original submission:  

There is in the NSURLConnectionDelegate protocol the method

-[connection:didFailWithError:]

which isn't called if a NSURLConnection is made to a dead
(not-listening) https service. I have attached the test cases
to be added to the Base's test suit.

Sergei Golovin <svg>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #31726:  test01.m added by svg (2KiB - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by svg (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-07-25 CaS StatusNone Fixed
        Open/ClosedOpen Closed
    2014-07-16 svg Attached File- Added test01.m, #31726

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code