Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion EXC_BAD_ACCESS on socket create

Date: Mon, 30 Jul 2012 13:28:26 -0700 (PDT)
From: Lassic <ori.ar...@gmail.com>
To: cocoahttpserver@googlegroups.com
Message-Id: <9a05958b-0362-443e-b1b8-cc9c5da3acb3@googlegroups.com>
In-Reply-To: <7728e0fb-204e-4f7e-952d-0073d2dc8b5f@googlegroups.com>
References: <7728e0fb-204e-4f7e-952d-0073d2dc8b5f@googlegroups.com>
Subject: Re: EXC_BAD_ACCESS on socket create
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_426_25232897.1343680106561"

------=_Part_426_25232897.1343680106561
Content-Type: multipart/alternative; 
	boundary="----=_Part_427_28399227.1343680106561"

------=_Part_427_28399227.1343680106561
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Wow, finally figured it out, and indeed it isn't related to either 
libraries, so you can remove this thread.
To anyone interested in a really freaky bug read on:
It turns out a different programmer on my team defined a static/global 
object in some XSocket.mm file:
XSocket *socket;

I figured this out since gdb said that:
gdb> p socket
$1  = <class XScoket *> 0x...... (or something similar, it's from my head)

I was expecting it to be the same as other functions in the socket.h 
header, but it was pointing to one of our classes!
So I tracked that symbol down and found that awful declaration...
After removing that it just worked. Sometimes debugging is an adventure, 
sorry for the noise.

Lassic.


On Monday, July 30, 2012 9:35:26 PM UTC+3, Lassic wrote:
>
> Hi,
> I know this is not directly related to CocoaHTTPServer, and maybe not even 
> GCDAsyncSocket, but I'm 
> really hoping someone can point me in the right direction.
> I'm integrating this server in a non-arc project, and followed the steps 
> required to compile this project's files and dependency files as ARC.
> (I might have missed something, but made sure of correct LLVM compiler and 
> -fobjc-arc flags).
>
> The debugger breaks with EXC_BAD_ACCESS on this line:
>
> socket4FD = createSocket(AF_INET, interface4);
> but I can actually set the last breakpoint inside that block before a 
> crash on:
> int socketFD = socket(domain, SOCK_STREAM, 0); // <-- crash
>
> It always crashes in the same place, the stack doesn't offer any help, 
> enabling zombies or allocations doesn't help:
>
> GCDAsyncSocket: Creating IPv4 socket 
> (lldb) bt 
> * thread #1: tid = 0x1c03, MyApp, stop reason = EXC_BAD_ACCESS (code=2, 
> address=0x947e28) 
> frame #0: MyApp 
> frame #1: 0x003be484 MyApp `__47-[GCDAsyncSocket 
> acceptOnInterface:port:error:]_block_invoke_0229 + 1276 at 
> GCDAsyncSocket.m:1585 
> frame #2: 0x33b9a796 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 
> 22 
> frame #3: 0x33b9a60a libdispatch.dylib`dispatch_barrier_sync_f$VARIANT$up 
> + 62
>
>
> I'm starting the server like so:
>
> -(id)init:(NSString *) docRootPath { 
>
> self = [super init]; 
>
> [DDLog addLogger:[DDTTYLogger sharedInstance]]; 
>
> // create http server 
>
> httpServer = [[HTTPServer alloc] init]; 
>
> // [httpServer setType:@"_http._tcp."]; // don't want bonjour at this 
> point 
>
> [httpServer setPort:49494]; // I also tried with dynamic port (comment out 
> this line)
>
> DDLogInfo(@"Setting document root: %@", docRootPath); // this prints a 
> good string
>
> [httpServer setDocumentRoot:docRootPath]; 
> // Start the server (and check for problems) 
> NSError *error = nil; 
> if([httpServer start:&error]) 
> { 
>
> DDLogInfo(@"Started HTTP Server on port %hu", [httpServer listeningPort]); 
>
> } 
> else 
> { 
>
> DDLogError(@"Error starting HTTP Server: %@", error); 
>
> }
>
> return self; 
>
> } 
>
>
>
On Monday, July 30, 2012 9:35:26 PM UTC+3, Lassic wrote:
>
> Hi,
> I know this is not directly related to CocoaHTTPServer, and maybe not even 
> GCDAsyncSocket, but I'm 
> really hoping someone can point me in the right direction.
> I'm integrating this server in a non-arc project, and followed the steps 
> required to compile this project's files and dependency files as ARC.
> (I might have missed something, but made sure of correct LLVM compiler and 
> -fobjc-arc flags).
>
> The debugger breaks with EXC_BAD_ACCESS on this line:
>
> socket4FD = createSocket(AF_INET, interface4);
> but I can actually set the last breakpoint inside that block before a 
> crash on:
> int socketFD = socket(domain, SOCK_STREAM, 0); // <-- crash
>
> It always crashes in the same place, the stack doesn't offer any help, 
> enabling zombies or allocations doesn't help:
>
> GCDAsyncSocket: Creating IPv4 socket 
> (lldb) bt 
> * thread #1: tid = 0x1c03, MyApp, stop reason = EXC_BAD_ACCESS (code=2, 
> address=0x947e28) 
> frame #0: MyApp 
> frame #1: 0x003be484 MyApp `__47-[GCDAsyncSocket 
> acceptOnInterface:port:error:]_block_invoke_0229 + 1276 at 
> GCDAsyncSocket.m:1585 
> frame #2: 0x33b9a796 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 
> 22 
> frame #3: 0x33b9a60a libdispatch.dylib`dispatch_barrier_sync_f$VARIANT$up 
> + 62
>
>
> I'm starting the server like so:
>
> -(id)init:(NSString *) docRootPath { 
>
> self = [super init]; 
>
> [DDLog addLogger:[DDTTYLogger sharedInstance]]; 
>
> // create http server 
>
> httpServer = [[HTTPServer alloc] init]; 
>
> // [httpServer setType:@"_http._tcp."]; // don't want bonjour at this 
> point 
>
> [httpServer setPort:49494]; // I also tried with dynamic port (comment out 
> this line)
>
> DDLogInfo(@"Setting document root: %@", docRootPath); // this prints a 
> good string
>
> [httpServer setDocumentRoot:docRootPath]; 
> // Start the server (and check for problems) 
> NSError *error = nil; 
> if([httpServer start:&error]) 
> { 
>
> DDLogInfo(@"Started HTTP Server on port %hu", [httpServer listeningPort]); 
>
> } 
> else 
> { 
>
> DDLogError(@"Error starting HTTP Server: %@", error); 
>
> }
>
> return self; 
>
> } 
>
>
>
------=_Part_427_28399227.1343680106561
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Wow, finally figured it out, and indeed it isn't related to either librarie=
s, so you can remove this thread.<div>To anyone interested in a really frea=
ky bug read on:</div><div>It turns out a different programmer on my team de=
fined a static/global object in some XSocket.mm file:</div><div>XSocket *so=
cket;</div><div><br></div><div>I figured this out since gdb said that:</div=
><div>gdb&gt; p socket</div><div>$1 &nbsp;=3D &lt;class XScoket *&gt; 0x...=
... (or something similar, it's from my head)</div><div><br></div><div>I wa=
s expecting it to be the same as other functions in the socket.h header, bu=
t it was pointing to one of our classes!</div><div>So I tracked that symbol=
 down and found that awful declaration...<br>After removing that it just wo=
rked. Sometimes debugging is an adventure, sorry for the noise.</div><div><=
br></div><div>Lassic.<br><br><br>On Monday, July 30, 2012 9:35:26 PM UTC+3,=
 Lassic wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Hi,<div>I know t=
his is not directly related to CocoaHTTPServer, and maybe not even GCDAsync=
Socket, but I'm&nbsp;</div><div>really hoping someone can point me in the r=
ight direction.</div><div>I'm integrating this server in a non-arc project,=
 and followed the steps required to compile this project's files and depend=
ency files as ARC.</div><div>(I might have missed something, but made sure =
of correct LLVM compiler and -fobjc-arc flags).</div><div><br></div><div>Th=
e debugger breaks with EXC_BAD_ACCESS on this line:</div><div>







<p><span>socket4FD</span> =3D createSocket(<span>AF_INET</span>, interface4=
);</p>but I can actually set the last breakpoint inside that block before a=
 crash on:<br>int socketFD =3D socket(domain, SOCK_STREAM, 0); // &lt;-- cr=
ash<br><br>It always crashes in the same place, the stack doesn't offer any=
 help, enabling zombies or allocations doesn't help:</div><div> <br>GCDAsyn=
cSocket: Creating IPv4 socket <br>(lldb) bt <br>* thread #1: tid =3D 0x1c03=
,  MyApp, stop reason =3D EXC_BAD_ACCESS (code=3D2, address=3D0x947e28) <br=
>    frame #0:  MyApp <br>    frame #1: 0x003be484 MyApp `__47-[GCDAsyncSoc=
ket acceptOnInterface:port:error:]<wbr>_block_invoke_0229 + 1276 at GCDAsyn=
cSocket.m:1585 <br>    frame #2: 0x33b9a796 libdispatch.dylib`_dispatch_<wb=
r>barrier_sync_f_invoke + 22 <br>    frame #3: 0x33b9a60a libdispatch.dylib=
`dispatch_<wbr>barrier_sync_f$VARIANT$up + 62<br><br><br>I'm starting the s=
erver like so:<br><br></div><div>-(id)init:(NSString *) docRootPath {&nbsp;=
</div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div>=
<p>    self =3D [super init]; </p></div><div><p>    [DDLog addLogger:[DDTTY=
Logger sharedInstance]]; </p></div><div><p>    // create http server </p></=
div><div><p>    httpServer =3D [[HTTPServer alloc] init]; </p></div><div><p=
>// [httpServer setType:@"_http._tcp."]; // don't want bonjour at this poin=
t&nbsp;</p></div><div><p> [httpServer setPort:49494]; // I also tried with =
dynamic port (comment out this line)</p></div><div><p> DDLogInfo(@"Setting =
document root: %@", docRootPath); // this prints a good string</p></div><di=
v><p> [httpServer setDocumentRoot:docRootPath];&nbsp;</p></div><div>// Star=
t the server (and check for problems) </div><div>NSError *error =3D nil; </=
div><div>if([httpServer start:&amp;error]) </div><div>{ </div></blockquote>=
<blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><blockquote=
 style=3D"margin:0 0 0 40px;border:none;padding:0px"><div>DDLogInfo(@"Start=
ed HTTP Server on port %hu", [httpServer listeningPort]); </div></blockquot=
e></blockquote><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0=
px"><div>} </div><div>else </div><div>{ </div></blockquote><blockquote styl=
e=3D"margin:0 0 0 40px;border:none;padding:0px"><blockquote style=3D"margin=
:0 0 0 40px;border:none;padding:0px"><div>DDLogError(@"Error starting HTTP =
Server: %@", error); </div></blockquote></blockquote><blockquote style=3D"m=
argin:0 0 0 40px;border:none;padding:0px"><div>}</div><div><br></div><div>r=
eturn self; </div></blockquote><div>} <br><p><br></p><p></p></div></blockqu=
ote></div><br>On Monday, July 30, 2012 9:35:26 PM UTC+3, Lassic wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;">Hi,<div>I know this is not directly=
 related to CocoaHTTPServer, and maybe not even GCDAsyncSocket, but I'm&nbs=
p;</div><div>really hoping someone can point me in the right direction.</di=
v><div>I'm integrating this server in a non-arc project, and followed the s=
teps required to compile this project's files and dependency files as ARC.<=
/div><div>(I might have missed something, but made sure of correct LLVM com=
piler and -fobjc-arc flags).</div><div><br></div><div>The debugger breaks w=
ith EXC_BAD_ACCESS on this line:</div><div>







<p><span>socket4FD</span> =3D createSocket(<span>AF_INET</span>, interface4=
);</p>but I can actually set the last breakpoint inside that block before a=
 crash on:<br>int socketFD =3D socket(domain, SOCK_STREAM, 0); // &lt;-- cr=
ash<br><br>It always crashes in the same place, the stack doesn't offer any=
 help, enabling zombies or allocations doesn't help:</div><div> <br>GCDAsyn=
cSocket: Creating IPv4 socket <br>(lldb) bt <br>* thread #1: tid =3D 0x1c03=
,  MyApp, stop reason =3D EXC_BAD_ACCESS (code=3D2, address=3D0x947e28) <br=
>    frame #0:  MyApp <br>    frame #1: 0x003be484 MyApp `__47-[GCDAsyncSoc=
ket acceptOnInterface:port:error:]<wbr>_block_invoke_0229 + 1276 at GCDAsyn=
cSocket.m:1585 <br>    frame #2: 0x33b9a796 libdispatch.dylib`_dispatch_<wb=
r>barrier_sync_f_invoke + 22 <br>    frame #3: 0x33b9a60a libdispatch.dylib=
`dispatch_<wbr>barrier_sync_f$VARIANT$up + 62<br><br><br>I'm starting the s=
erver like so:<br><br></div><div>-(id)init:(NSString *) docRootPath {&nbsp;=
</div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div>=
<p>    self =3D [super init]; </p></div><div><p>    [DDLog addLogger:[DDTTY=
Logger sharedInstance]]; </p></div><div><p>    // create http server </p></=
div><div><p>    httpServer =3D [[HTTPServer alloc] init]; </p></div><div><p=
>// [httpServer setType:@"_http._tcp."]; // don't want bonjour at this poin=
t&nbsp;</p></div><div><p> [httpServer setPort:49494]; // I also tried with =
dynamic port (comment out this line)</p></div><div><p> DDLogInfo(@"Setting =
document root: %@", docRootPath); // this prints a good string</p></div><di=
v><p> [httpServer setDocumentRoot:docRootPath];&nbsp;</p></div><div>// Star=
t the server (and check for problems) </div><div>NSError *error =3D nil; </=
div><div>if([httpServer start:&amp;error]) </div><div>{ </div></blockquote>=
<blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><blockquote=
 style=3D"margin:0 0 0 40px;border:none;padding:0px"><div>DDLogInfo(@"Start=
ed HTTP Server on port %hu", [httpServer listeningPort]); </div></blockquot=
e></blockquote><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0=
px"><div>} </div><div>else </div><div>{ </div></blockquote><blockquote styl=
e=3D"margin:0 0 0 40px;border:none;padding:0px"><blockquote style=3D"margin=
:0 0 0 40px;border:none;padding:0px"><div>DDLogError(@"Error starting HTTP =
Server: %@", error); </div></blockquote></blockquote><blockquote style=3D"m=
argin:0 0 0 40px;border:none;padding:0px"><div>}</div><div><br></div><div>r=
eturn self; </div></blockquote><div>} <br><p><br></p><p></p></div></blockqu=
ote>
------=_Part_427_28399227.1343680106561--

------=_Part_426_25232897.1343680106561--