MACH_Exception EXC_BAD_INSTRUCTION EXC_ARM_UNDEFINED fault_address:0x0000000108460684
huuang opened this issue · comments
huang commented
Had a EXC_BAD_INSTRUCTION EXC_ARM_UNDEFINED
issue on code -[GCDWebServer(Extensions) startWithPort:bonjourName:](GCDWebServer.m:828)
when I created a GCDWebServer instance and started it in a dispatch_once
block. Below is my code, any ideas will be appreciated.
@interface HttpServerManager()
@property (nonatomic, strong) GCDWebServer *webServer;
@property (nonatomic, assign) UInt16 port;
@end
@implementation HttpServerManager
+ (instancetype)sharedInstance
{
static HttpServerManager *instance;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
instance = [HttpServerManager new];
[GCDWebServer setLogLevel: 3];
});
return instance;
}
- (instancetype)init
{
self = [super init];
if (self) {
_webServer = [GCDWebServer new];
[_webServer addHandlerWithMatchBlock: ^GCDWebServerRequest * _Nullable(NSString * _Nonnull requestMethod, NSURL * _Nonnull requestURL, NSDictionary<NSString *,NSString *> * _Nonnull requestHeaders, NSString * _Nonnull urlPath, NSDictionary<NSString *,NSString *> * _Nonnull urlQuery) {
return [[GCDWebServerDataRequest alloc] initWithMethod: requestMethod url: requestURL headers: requestHeaders path: urlPath query: urlQuery];
} asyncProcessBlock: [self asyncProcessBlock]];
[self startServer];
}
return self;
}
- (void)startServer
{
if (self.webServer.isRunning == NO) {
BOOL success = NO;
for (int port = 8190; port < 8290; port++) {
success = [self.webServer startWithPort: port bonjourName: nil];
if (success) {
self.port = port;
break;
}
}
}
}
@end