File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,21 +104,24 @@ class HostsEditor {
104104 }
105105
106106 private func flushDNSCache( ) {
107- let task = Process ( )
108- task. launchPath = " /usr/bin/dscacheutil "
109- task. arguments = [ " -flushcache " ]
110- try ? task. run ( )
111- task. waitUntilExit ( )
112-
113- guard let pid = mDNSResponderPID ( ) else {
114- log ( " WARN: could not find mDNSResponder PID — DNS cache not flushed via HUP " )
115- return
107+ // run async so a hung process can't block the main RunLoop timer
108+ DispatchQueue . global ( qos: . utility) . async {
109+ let task = Process ( )
110+ task. launchPath = " /usr/bin/dscacheutil "
111+ task. arguments = [ " -flushcache " ]
112+ try ? task. run ( )
113+ task. waitUntilExit ( )
114+
115+ guard let pid = mDNSResponderPID ( ) else {
116+ log ( " WARN: could not find mDNSResponder PID — DNS cache not flushed via HUP " )
117+ return
118+ }
119+ let task2 = Process ( )
120+ task2. launchPath = " /bin/kill "
121+ task2. arguments = [ " -HUP " , String ( pid) ]
122+ try ? task2. run ( )
123+ task2. waitUntilExit ( )
116124 }
117- let task2 = Process ( )
118- task2. launchPath = " /bin/kill "
119- task2. arguments = [ " -HUP " , String ( pid) ]
120- try ? task2. run ( )
121- task2. waitUntilExit ( )
122125 }
123126
124127 private func mDNSResponderPID( ) -> Int32 ? {
You can’t perform that action at this time.
0 commit comments