The Trunk: Network-nice.246.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Network-nice.246.mcz

commits-2
Nicolas Cellier uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-nice.246.mcz

==================== Summary ====================

Name: Network-nice.246
Author: nice
Time: 12 April 2021, 5:35:00.782058 pm
UUID: 09001f79-2f03-bb46-be00-2b54f5b89d36
Ancestors: Network-mt.245

Redo the fix from Network-ct.242 with a slighlty different implementation:

1) use exception retry
2) avoid using in: aBlock where a temporary would do the job.

Thanks to Christophe for original report and fix!
(https://source.squeak.org/treated/Network-ct.242.diff)
Original commit message below:

Fixes two MNUs that can occur during connecting to an unavailable network resource.

Bug #1 (stream>>>#timeout:)

        Steps to reproduce:
        1. Start your image while an internet connection is available. Make any connection attempt (e.g. refresh a Monticello HTTP(s) repository) to ensure that the network is initialized (NetNameResolver initializeNetwork).
        2. There are two alternative scenarios:
                2.(i) Do it:
                        WebClient httpGet: 'https://foo.bar'.
                2.(ii) Turn off your internet connection (e.g. disable your WLAN adapter). Then make another connection attempt.
       
        In both scenarios, you will see the following error:
                        MessageNotUnderstood: UndefinedObject>>timeout: (stream)
                        WebClient>>connect
                        WebClient>>sendRequest:contentBlock:
                        ...
       
        This bug occurred because there was no check for the presence of any network socket for the request host/port.

Bug #2 (#findNextHandlerContextStarting):

        Steps to reproduce:
                Do it:
                        WebClient httpGet: 'https://'.
       
        Error:
                MessageNotUnderstood: UndefinedObject>>findNextHandlerContextStarting
                Context>>nextHandlerContext
                ConnectionRefused(Exception)>>pass
                ...

=============== Diff against Network-mt.245 ===============

Item was changed:
  ----- Method: SocketStream class>>openConnectionToHostNamed:port: (in category 'instance creation') -----
  openConnectionToHostNamed: hostName port: portNumber
 
+ | addressInformations stream |
  NetNameResolver useOldNetwork
  ifTrue: [ | hostIP |
  hostIP := NetNameResolver addressForName: hostName timeout: 20.
  hostIP ifNil: [NetworkError signal: ('Cannot resolve {1}.' format: {hostName})].
+ ^self openConnectionToHost: hostIP port: portNumber].
+ addressInformations := SocketAddressInformation
+ forHost: hostName
+ service: portNumber asString
+ flags: 0
+ addressFamily: 0
+ socketType: SocketAddressInformation socketTypeStream
+ protocol: SocketAddressInformation protocolTCP.
+ addressInformations ifEmpty: [
+ NoNetworkError signal: ('Could not find a network for {1} on port {2}' translated format: {hostName. portNumber})].
+ stream := addressInformations readStream.
+ ^ [self on: stream next connect] on: NetworkError
+ do: [:exc | stream atEnd
+ ifTrue:
+ ["No more address to retry, pass the exception to upper level"
+ exc pass]
+ ifFalse:
+ ["retry with next address"
+ exc retry]].!
- ^self openConnectionToHost: hostIP port: portNumber]
- ifFalse: [| addressInformations lastError |
- addressInformations := SocketAddressInformation
- forHost: hostName
- service: portNumber asString
- flags: 0
- addressFamily: 0
- socketType: SocketAddressInformation socketTypeStream
- protocol: SocketAddressInformation protocolTCP.
- addressInformations do: [:addressInformation |
- [^ self on: addressInformation connect] on: NetworkError do: [:e | lastError := e]].
- ^ lastError ifNotNil: [:e | e pass]]!