[squeak-dev] The Inbox: Network-ct.242.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Sep 3 11:05:03 UTC 2020


Christoph Thiede uploaded a new version of Network to project The Inbox:
http://source.squeak.org/inbox/Network-ct.242.mcz

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

Name: Network-ct.242
Author: ct
Time: 3 September 2020, 1:05:00.729083 pm
UUID: 8c331b27-3e86-aa41-bc42-910d53097713
Ancestors: Network-eem.241

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
		...
	
	This bug was related to the unorthodox way of exception handling in the unpatched method when trying to connect to the different available sockets. You cannot pass an exception if its context is dead, so I used recursion instead, which also has the advantage that every exception from every socket is stored on the stack and can be explored by users encountering an error.

Also improves multilingual support.

Please review!
- Is SocketStream the right place to signal the NoNetworkError? (Because of its enumerative character, I found SocketAddressInformation>>#forHost:service:flags:addressFamily:socketType:protocol:) appropriate to return an empty collection.

=============== Diff against Network-eem.241 ===============

Item was changed:
  ----- Method: SocketStream class>>openConnectionToHostNamed:port: (in category 'instance creation') -----
  openConnectionToHostNamed: hostName port: portNumber
  	
+ 	| addressInformations |
+ 	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})].
+ 	
+ 	addressInformations readStream in: [:stream |
+ 		| connectBlock |
+ 		connectBlock := [
+ 			[^ self on: stream next connect]
+ 				on: NetworkError do: [:error |
+ 					stream atEnd
+ 						ifFalse: connectBlock "ignore and try next"
+ 						ifTrue: [error pass]]].
+ 		^ connectBlock value].!
- 	NetNameResolver useOldNetwork
- 		ifTrue: [	| hostIP |
- 			hostIP := NetNameResolver addressForName: hostName timeout: 20.
- 			hostIP ifNil: [NetworkError signal: ('Cannot resolve {1}.' format: {hostName})].
- 			^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]]!



More information about the Squeak-dev mailing list