Skip to content

ProfileRecorderServer/Server.swift:338: Fatal error: Unexpectedly found nil while unwrapping an Optional value #43

@vsarunas

Description

@vsarunas

I'm registering the profile service into Consul with a health check so that list of targets to profile could be automatically determined.
Since HTTP check has no endpoint which returns 200, had to switch to a TCP session health check, which unfortunately causes this force unwrap to fail:

ProfileRecorderServer/Server.swift:338: Fatal error: Unexpectedly found nil while unwrapping an Optional value

(lldb) p child.channel
warning: TypeSystemSwiftTypeRef::GetNumChildren: had to engage SwiftASTContext fallback for type $s8NIOPosix27MultiThreadedEventLoopGroupCD(NIOPosix.SocketChannel) 0x0000000bd8709dc0 {
  NIOPosix.BaseStreamSocketChannel<NIOPosix.Socket> = {
    NIOPosix.BaseSocketChannel<NIOPosix.Socket> = {
      parent = 0x0000000bd5e27900 {
        NIOPosix.BaseSocketChannel<NIOPosix.ServerSocket> ={...}
        backlog = 128{...}
        group = 0x0000000bd84b45f0{...}
      }
      socket = 0x0000000bd6bcdde0 {
        NIOPosix.BaseSocket ={...}
      }
      closePromise = {
        futureResult = 0x0000000bd6a2eb20{...}
      }
      selectableEventLoop = 0x0000000bd5c9a3e0 {
        _selector = 0x0000000bd8902fd0{...}
        thread = 0x0000000bd58a63d0{...}
        _pendingTaskPop = false{...}
        scheduledTaskCounter = 0x0000000bd65a69e0{...}
        _scheduledTasks ={...}
        _immediateTasks ={...}
        _uniqueID ={...}
        tasksCopy = 0 values{...}
        _succeededVoidFuture = 0x0000000bd58359f0{...}
        canBeShutdownIndividually = false{...}
        _tasksLock ={...}
        _externalStateLock ={...}
        internalState = runningAndAcceptingNewRegistrations{...}
        externalState = open{...}
        bufferPool = 0x0000000bd88d78c0{...}
        msgBufferPool = 0x0000000bd65a69c0{...}
        _parentGroup = 0x0000000bd84b45f0{...}
        promiseCreationStoreLock ={...}
        _promiseCreationStore = 2 key/value pairs{...}
        metricsDelegate = nil{...}
        lastTickEndTime ={...}
      }
      _offEventLoopLock = {
        _storage = 0x0000000bd9418140{...}
      }
      isActiveAtomic = 0x0000000bd80052a0 (__storage = Swift.Bool.AtomicRepresentation @ 0x0000000bd80052b0)
      socketDescription = "BaseSocket { fd=172 }"
      readPending = true
      pendingConnect = nil
      recvBufferPool = {
        _buffer = some{...}
        _buffers = 0 values{...}
        _lastUsedIndex = 0{...}
        capacity = 4{...}
        recvAllocator ={...}
        _mayGrow = false{...}
      }
      maxMessagesPerRead = 4
      inFlushNow = false
      autoRead = true
      _pipeline = 0x0000000bd6609ea0 {
        head = nil{...}
        tail = nil{...}
        idx = 8{...}
        destroyed = true{...}
        eventLoop = 0x0000000bd5c9a3e0{...}
        _channel = nil{...}
      }
      _addressCache = {
        local = nil{...}
        remote = nil{...}
      }
      _bufferAllocatorCache = {
        malloc = 90 a0 63 0a 01 00 00 00{...}
        realloc = d0 a0 63 0a 01 00 00 00{...}
        free ={...}
        memcpy ={...}
      }
      interestedEvent = (rawValue = 1)
      lifecycleManager = {
        eventLoop = 0x0000000bd5c9a3e0{...}
        isActiveAtomic = 0x0000000bd80052a0{...}
        hasSeenEOFNotification = true{...}
        supportsReconnect = false{...}
        currentState = closed{...}
      }
      bufferAllocator = {
        malloc = 90 a0 63 0a 01 00 00 00{...}
        realloc = d0 a0 63 0a 01 00 00 00{...}
        free ={...}
        memcpy ={...}
      }
    }
    connectTimeoutScheduled = none
    allowRemoteHalfClosure = false
    inputShutdown = false
    outputShutdown = false
    pendingWrites = 0x0000000bd5521d60 {
      state = {
        pendingWrites ={...}
        bytes = 0{...}
      }
      bufferPool = 0x0000000bd88d78c0 {
        maxSize = 16{...}
        elements = 0 values{...}
      }
      waterMark = (low = 32768, high = 65536)
      channelWritabilityFlag = 0x0000000bd8004de0 (__storage = Swift.Bool.AtomicRepresentation @ 0x0000000bd8004df0)
      publishedWritability = true
      writeSpinCount = 16
      isOpen = false
      outboundCloseState = closed
    }
  }
  connectTimeout = nil
}

The crash can be reproduced with simple connect and immediate close:

python3 -c "import socket; s=socket.socket(); s.connect(('localhost',59349)); s.close()"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions