ClientConnectionHandler.swift 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Copyright 2024, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import NIOCore
  17. import NIOHTTP2
  18. /// An event which happens on a client's HTTP/2 connection.
  19. package enum ClientConnectionEvent: Sendable {
  20. package enum CloseReason: Sendable {
  21. /// The server sent a GOAWAY frame to the client.
  22. case goAway(HTTP2ErrorCode, String)
  23. /// The keep alive timer fired and subsequently timed out.
  24. case keepaliveExpired
  25. /// The connection became idle.
  26. case idle
  27. /// The local peer initiated the close.
  28. case initiatedLocally
  29. /// The connection was closed unexpectedly
  30. case unexpected((any Error)?, isIdle: Bool)
  31. }
  32. /// The connection is now ready.
  33. case ready
  34. /// The connection has started shutting down, no new streams should be created.
  35. case closing(CloseReason)
  36. }
  37. /// A `ChannelHandler` which manages part of the lifecycle of a gRPC connection over HTTP/2.
  38. ///
  39. /// This handler is responsible for managing several aspects of the connection. These include:
  40. /// 1. Periodically sending keep alive pings to the server (if configured) and closing the
  41. /// connection if necessary.
  42. /// 2. Closing the connection if it is idle (has no open streams) for a configured amount of time.
  43. /// 3. Forwarding lifecycle events to the next handler.
  44. ///
  45. /// Some of the behaviours are described in [gRFC A8](https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md).
  46. package final class ClientConnectionHandler: ChannelInboundHandler, ChannelOutboundHandler {
  47. package typealias InboundIn = HTTP2Frame
  48. package typealias InboundOut = ClientConnectionEvent
  49. package typealias OutboundIn = Never
  50. package typealias OutboundOut = HTTP2Frame
  51. package enum OutboundEvent: Hashable, Sendable {
  52. /// Close the connection gracefully
  53. case closeGracefully
  54. }
  55. /// The `EventLoop` of the `Channel` this handler exists in.
  56. private let eventLoop: any EventLoop
  57. /// The maximum amount of time the connection may be idle for. If the connection remains idle
  58. /// (i.e. has no open streams) for this period of time then the connection will be gracefully
  59. /// closed.
  60. private var maxIdleTimer: Timer?
  61. /// The amount of time to wait before sending a keep alive ping.
  62. private var keepaliveTimer: Timer?
  63. /// The amount of time the client has to reply after sending a keep alive ping. Only used if
  64. /// `keepaliveTimer` is set.
  65. private var keepaliveTimeoutTimer: Timer
  66. /// Opaque data sent in keep alive pings.
  67. private let keepalivePingData: HTTP2PingData
  68. /// The current state of the connection.
  69. private var state: StateMachine
  70. /// Whether a flush is pending.
  71. private var flushPending: Bool
  72. /// Whether `channelRead` has been called and `channelReadComplete` hasn't yet been called.
  73. /// Resets once `channelReadComplete` returns.
  74. private var inReadLoop: Bool
  75. /// The context of the channel this handler is in.
  76. private var context: ChannelHandlerContext?
  77. /// Creates a new handler which manages the lifecycle of a connection.
  78. ///
  79. /// - Parameters:
  80. /// - eventLoop: The `EventLoop` of the `Channel` this handler is placed in.
  81. /// - maxIdleTime: The maximum amount time a connection may be idle for before being closed.
  82. /// - keepaliveTime: The amount of time to wait after reading data before sending a keep-alive
  83. /// ping.
  84. /// - keepaliveTimeout: The amount of time the client has to reply after the server sends a
  85. /// keep-alive ping to keep the connection open. The connection is closed if no reply
  86. /// is received.
  87. /// - keepaliveWithoutCalls: Whether the client sends keep-alive pings when there are no calls
  88. /// in progress.
  89. package init(
  90. eventLoop: any EventLoop,
  91. maxIdleTime: TimeAmount?,
  92. keepaliveTime: TimeAmount?,
  93. keepaliveTimeout: TimeAmount?,
  94. keepaliveWithoutCalls: Bool
  95. ) {
  96. self.eventLoop = eventLoop
  97. self.maxIdleTimer = maxIdleTime.map { Timer(delay: $0) }
  98. self.keepaliveTimer = keepaliveTime.map { Timer(delay: $0, repeat: true) }
  99. self.keepaliveTimeoutTimer = Timer(delay: keepaliveTimeout ?? .seconds(20))
  100. self.keepalivePingData = HTTP2PingData(withInteger: .random(in: .min ... .max))
  101. self.state = StateMachine(allowKeepaliveWithoutCalls: keepaliveWithoutCalls)
  102. self.flushPending = false
  103. self.inReadLoop = false
  104. }
  105. package func handlerAdded(context: ChannelHandlerContext) {
  106. assert(context.eventLoop === self.eventLoop)
  107. self.context = context
  108. }
  109. package func handlerRemoved(context: ChannelHandlerContext) {
  110. self.context = nil
  111. }
  112. package func channelInactive(context: ChannelHandlerContext) {
  113. switch self.state.closed() {
  114. case .none:
  115. ()
  116. case .unexpectedClose(let error, let isIdle):
  117. let event = self.wrapInboundOut(.closing(.unexpected(error, isIdle: isIdle)))
  118. context.fireChannelRead(event)
  119. case .succeed(let promise):
  120. promise.succeed()
  121. }
  122. self.keepaliveTimer?.cancel()
  123. self.keepaliveTimeoutTimer.cancel()
  124. }
  125. package func userInboundEventTriggered(context: ChannelHandlerContext, event: Any) {
  126. switch event {
  127. case let event as NIOHTTP2StreamCreatedEvent:
  128. self._streamCreated(event.streamID, channel: context.channel)
  129. case let event as StreamClosedEvent:
  130. self._streamClosed(event.streamID, channel: context.channel)
  131. default:
  132. ()
  133. }
  134. context.fireUserInboundEventTriggered(event)
  135. }
  136. package func errorCaught(context: ChannelHandlerContext, error: any Error) {
  137. // Store the error and close, this will result in the final close event being fired down
  138. // the pipeline with an appropriate close reason and appropriate error. (This avoids
  139. // the async channel just throwing the error.)
  140. self.state.receivedError(error)
  141. context.close(mode: .all, promise: nil)
  142. }
  143. package func channelRead(context: ChannelHandlerContext, data: NIOAny) {
  144. let frame = self.unwrapInboundIn(data)
  145. self.inReadLoop = true
  146. switch frame.payload {
  147. case .goAway(_, let errorCode, let data):
  148. // Receiving a GOAWAY frame means we need to stop creating streams immediately and start
  149. // closing the connection.
  150. switch self.state.beginGracefulShutdown(promise: nil) {
  151. case .sendGoAway(let close):
  152. // gRPC servers may indicate why the GOAWAY was sent in the opaque data.
  153. let message = data.map { String(buffer: $0) } ?? ""
  154. context.fireChannelRead(self.wrapInboundOut(.closing(.goAway(errorCode, message))))
  155. // Clients should send GOAWAYs when closing a connection.
  156. self.writeAndFlushGoAway(context: context, errorCode: .noError)
  157. if close {
  158. context.close(promise: nil)
  159. }
  160. case .none:
  161. ()
  162. }
  163. case .ping(let data, let ack):
  164. // Pings are ack'd by the HTTP/2 handler so we only pay attention to acks here, and in
  165. // particular only those carrying the keep-alive data.
  166. if ack, data == self.keepalivePingData {
  167. let loopBound = LoopBoundView(handler: self, context: context)
  168. self.keepaliveTimeoutTimer.cancel()
  169. self.keepaliveTimer?.schedule(on: context.eventLoop) {
  170. loopBound.keepaliveTimerFired()
  171. }
  172. }
  173. case .settings(.settings(_)):
  174. let isInitialSettings = self.state.receivedSettings()
  175. // The first settings frame indicates that the connection is now ready to use. The channel
  176. // becoming active is insufficient as, for example, a TLS handshake may fail after
  177. // establishing the TCP connection, or the server isn't configured for gRPC (or HTTP/2).
  178. if isInitialSettings {
  179. let loopBound = LoopBoundView(handler: self, context: context)
  180. self.keepaliveTimer?.schedule(on: context.eventLoop) {
  181. loopBound.keepaliveTimerFired()
  182. }
  183. self.maxIdleTimer?.schedule(on: context.eventLoop) {
  184. loopBound.maxIdleTimerFired()
  185. }
  186. context.fireChannelRead(self.wrapInboundOut(.ready))
  187. }
  188. default:
  189. ()
  190. }
  191. }
  192. package func channelReadComplete(context: ChannelHandlerContext) {
  193. while self.flushPending {
  194. self.flushPending = false
  195. context.flush()
  196. }
  197. self.inReadLoop = false
  198. context.fireChannelReadComplete()
  199. }
  200. package func triggerUserOutboundEvent(
  201. context: ChannelHandlerContext,
  202. event: Any,
  203. promise: EventLoopPromise<Void>?
  204. ) {
  205. if let event = event as? OutboundEvent {
  206. switch event {
  207. case .closeGracefully:
  208. switch self.state.beginGracefulShutdown(promise: promise) {
  209. case .sendGoAway(let close):
  210. context.fireChannelRead(self.wrapInboundOut(.closing(.initiatedLocally)))
  211. // The client could send a GOAWAY at this point but it's not really necessary, the server
  212. // can't open streams anyway, the client will just close the connection when it's done.
  213. if close {
  214. context.close(promise: nil)
  215. }
  216. case .none:
  217. ()
  218. }
  219. }
  220. } else {
  221. context.triggerUserOutboundEvent(event, promise: promise)
  222. }
  223. }
  224. }
  225. extension ClientConnectionHandler {
  226. struct LoopBoundView: @unchecked Sendable {
  227. private let handler: ClientConnectionHandler
  228. private let context: ChannelHandlerContext
  229. init(handler: ClientConnectionHandler, context: ChannelHandlerContext) {
  230. self.handler = handler
  231. self.context = context
  232. }
  233. func keepaliveTimerFired() {
  234. self.context.eventLoop.assertInEventLoop()
  235. self.handler.keepaliveTimerFired(context: self.context)
  236. }
  237. func keepaliveTimeoutExpired() {
  238. self.context.eventLoop.assertInEventLoop()
  239. self.handler.keepaliveTimeoutExpired(context: self.context)
  240. }
  241. func maxIdleTimerFired() {
  242. self.context.eventLoop.assertInEventLoop()
  243. self.handler.maxIdleTimerFired(context: self.context)
  244. }
  245. }
  246. }
  247. extension ClientConnectionHandler {
  248. package struct HTTP2StreamDelegate: @unchecked Sendable, NIOHTTP2StreamDelegate {
  249. // @unchecked is okay: the only methods do the appropriate event-loop dance.
  250. private let handler: ClientConnectionHandler
  251. init(_ handler: ClientConnectionHandler) {
  252. self.handler = handler
  253. }
  254. package func streamCreated(_ id: HTTP2StreamID, channel: any Channel) {
  255. if self.handler.eventLoop.inEventLoop {
  256. self.handler._streamCreated(id, channel: channel)
  257. } else {
  258. self.handler.eventLoop.execute {
  259. self.handler._streamCreated(id, channel: channel)
  260. }
  261. }
  262. }
  263. package func streamClosed(_ id: HTTP2StreamID, channel: any Channel) {
  264. if self.handler.eventLoop.inEventLoop {
  265. self.handler._streamClosed(id, channel: channel)
  266. } else {
  267. self.handler.eventLoop.execute {
  268. self.handler._streamClosed(id, channel: channel)
  269. }
  270. }
  271. }
  272. }
  273. package var http2StreamDelegate: HTTP2StreamDelegate {
  274. return HTTP2StreamDelegate(self)
  275. }
  276. private func _streamCreated(_ id: HTTP2StreamID, channel: any Channel) {
  277. self.eventLoop.assertInEventLoop()
  278. // Stream created, so the connection isn't idle.
  279. self.maxIdleTimer?.cancel()
  280. self.state.streamOpened(id)
  281. }
  282. private func _streamClosed(_ id: HTTP2StreamID, channel: any Channel) {
  283. guard let context = self.context else { return }
  284. self.eventLoop.assertInEventLoop()
  285. switch self.state.streamClosed(id) {
  286. case .startIdleTimer(let cancelKeepalive):
  287. // All streams are closed, restart the idle timer, and stop the keep-alive timer (it may
  288. // not stop if keep-alive is allowed when there are no active calls).
  289. let loopBound = LoopBoundView(handler: self, context: context)
  290. self.maxIdleTimer?.schedule(on: context.eventLoop) {
  291. loopBound.maxIdleTimerFired()
  292. }
  293. if cancelKeepalive {
  294. self.keepaliveTimer?.cancel()
  295. }
  296. case .close:
  297. // Connection was closing but waiting for all streams to close. They must all be closed
  298. // now so close the connection.
  299. context.close(promise: nil)
  300. case .none:
  301. ()
  302. }
  303. }
  304. }
  305. extension ClientConnectionHandler {
  306. private func maybeFlush(context: ChannelHandlerContext) {
  307. if self.inReadLoop {
  308. self.flushPending = true
  309. } else {
  310. context.flush()
  311. }
  312. }
  313. private func keepaliveTimerFired(context: ChannelHandlerContext) {
  314. guard self.state.sendKeepalivePing() else { return }
  315. // Cancel the keep alive timer when the client sends a ping. The timer is resumed when the ping
  316. // is acknowledged.
  317. self.keepaliveTimer?.cancel()
  318. let ping = HTTP2Frame(streamID: .rootStream, payload: .ping(self.keepalivePingData, ack: false))
  319. context.write(self.wrapOutboundOut(ping), promise: nil)
  320. self.maybeFlush(context: context)
  321. // Schedule a timeout on waiting for the response.
  322. let loopBound = LoopBoundView(handler: self, context: context)
  323. self.keepaliveTimeoutTimer.schedule(on: context.eventLoop) {
  324. loopBound.keepaliveTimeoutExpired()
  325. }
  326. }
  327. private func keepaliveTimeoutExpired(context: ChannelHandlerContext) {
  328. guard self.state.beginClosing() else { return }
  329. context.fireChannelRead(self.wrapInboundOut(.closing(.keepaliveExpired)))
  330. self.writeAndFlushGoAway(context: context, message: "keepalive_expired")
  331. context.close(promise: nil)
  332. }
  333. private func maxIdleTimerFired(context: ChannelHandlerContext) {
  334. guard self.state.beginClosing() else { return }
  335. context.fireChannelRead(self.wrapInboundOut(.closing(.idle)))
  336. self.writeAndFlushGoAway(context: context, message: "idle")
  337. context.close(promise: nil)
  338. }
  339. private func writeAndFlushGoAway(
  340. context: ChannelHandlerContext,
  341. errorCode: HTTP2ErrorCode = .noError,
  342. message: String? = nil
  343. ) {
  344. let goAway = HTTP2Frame(
  345. streamID: .rootStream,
  346. payload: .goAway(
  347. lastStreamID: 0,
  348. errorCode: errorCode,
  349. opaqueData: message.map { context.channel.allocator.buffer(string: $0) }
  350. )
  351. )
  352. context.write(self.wrapOutboundOut(goAway), promise: nil)
  353. self.maybeFlush(context: context)
  354. }
  355. }
  356. extension ClientConnectionHandler {
  357. struct StateMachine {
  358. private var state: State
  359. private enum State {
  360. case active(Active)
  361. case closing(Closing)
  362. case closed
  363. case _modifying
  364. struct Active {
  365. var openStreams: Set<HTTP2StreamID>
  366. var allowKeepaliveWithoutCalls: Bool
  367. var receivedConnectionPreface: Bool
  368. var error: (any Error)?
  369. init(allowKeepaliveWithoutCalls: Bool) {
  370. self.openStreams = []
  371. self.allowKeepaliveWithoutCalls = allowKeepaliveWithoutCalls
  372. self.receivedConnectionPreface = false
  373. self.error = nil
  374. }
  375. mutating func receivedSettings() -> Bool {
  376. let isFirstSettingsFrame = !self.receivedConnectionPreface
  377. self.receivedConnectionPreface = true
  378. return isFirstSettingsFrame
  379. }
  380. }
  381. struct Closing {
  382. var allowKeepaliveWithoutCalls: Bool
  383. var openStreams: Set<HTTP2StreamID>
  384. var closePromise: Optional<EventLoopPromise<Void>>
  385. init(from state: Active, closePromise: EventLoopPromise<Void>?) {
  386. self.openStreams = state.openStreams
  387. self.allowKeepaliveWithoutCalls = state.allowKeepaliveWithoutCalls
  388. self.closePromise = closePromise
  389. }
  390. }
  391. }
  392. init(allowKeepaliveWithoutCalls: Bool) {
  393. self.state = .active(State.Active(allowKeepaliveWithoutCalls: allowKeepaliveWithoutCalls))
  394. }
  395. /// Record that a SETTINGS frame was received from the remote peer.
  396. ///
  397. /// - Returns: `true` if this was the first SETTINGS frame received.
  398. mutating func receivedSettings() -> Bool {
  399. switch self.state {
  400. case .active(var active):
  401. self.state = ._modifying
  402. let isFirstSettingsFrame = active.receivedSettings()
  403. self.state = .active(active)
  404. return isFirstSettingsFrame
  405. case .closing, .closed:
  406. return false
  407. case ._modifying:
  408. preconditionFailure()
  409. }
  410. }
  411. /// Record that an error was received.
  412. mutating func receivedError(_ error: any Error) {
  413. switch self.state {
  414. case .active(var active):
  415. self.state = ._modifying
  416. active.error = error
  417. self.state = .active(active)
  418. case .closing, .closed:
  419. ()
  420. case ._modifying:
  421. preconditionFailure()
  422. }
  423. }
  424. /// Record that the stream with the given ID has been opened.
  425. mutating func streamOpened(_ id: HTTP2StreamID) {
  426. switch self.state {
  427. case .active(var state):
  428. self.state = ._modifying
  429. let (inserted, _) = state.openStreams.insert(id)
  430. assert(inserted, "Can't open stream \(Int(id)), it's already open")
  431. self.state = .active(state)
  432. case .closing(var state):
  433. self.state = ._modifying
  434. let (inserted, _) = state.openStreams.insert(id)
  435. assert(inserted, "Can't open stream \(Int(id)), it's already open")
  436. self.state = .closing(state)
  437. case .closed:
  438. ()
  439. case ._modifying:
  440. preconditionFailure()
  441. }
  442. }
  443. enum OnStreamClosed: Equatable {
  444. /// Start the idle timer, after which the connection should be closed gracefully.
  445. case startIdleTimer(cancelKeepalive: Bool)
  446. /// Close the connection.
  447. case close
  448. /// Do nothing.
  449. case none
  450. }
  451. /// Record that the stream with the given ID has been closed.
  452. mutating func streamClosed(_ id: HTTP2StreamID) -> OnStreamClosed {
  453. let onStreamClosed: OnStreamClosed
  454. switch self.state {
  455. case .active(var state):
  456. self.state = ._modifying
  457. let removedID = state.openStreams.remove(id)
  458. assert(removedID != nil, "Can't close stream \(Int(id)), it wasn't open")
  459. if state.openStreams.isEmpty {
  460. onStreamClosed = .startIdleTimer(cancelKeepalive: !state.allowKeepaliveWithoutCalls)
  461. } else {
  462. onStreamClosed = .none
  463. }
  464. self.state = .active(state)
  465. case .closing(var state):
  466. self.state = ._modifying
  467. let removedID = state.openStreams.remove(id)
  468. assert(removedID != nil, "Can't close stream \(Int(id)), it wasn't open")
  469. onStreamClosed = state.openStreams.isEmpty ? .close : .none
  470. self.state = .closing(state)
  471. case .closed:
  472. onStreamClosed = .none
  473. case ._modifying:
  474. preconditionFailure()
  475. }
  476. return onStreamClosed
  477. }
  478. /// Returns whether a keep alive ping should be sent to the server.
  479. func sendKeepalivePing() -> Bool {
  480. let sendKeepalivePing: Bool
  481. // Only send a ping if there are open streams or there are no open streams and keep alive
  482. // is permitted when there are no active calls.
  483. switch self.state {
  484. case .active(let state):
  485. sendKeepalivePing = !state.openStreams.isEmpty || state.allowKeepaliveWithoutCalls
  486. case .closing(let state):
  487. sendKeepalivePing = !state.openStreams.isEmpty || state.allowKeepaliveWithoutCalls
  488. case .closed:
  489. sendKeepalivePing = false
  490. case ._modifying:
  491. preconditionFailure()
  492. }
  493. return sendKeepalivePing
  494. }
  495. enum OnGracefulShutDown: Equatable {
  496. case sendGoAway(Bool)
  497. case none
  498. }
  499. mutating func beginGracefulShutdown(promise: EventLoopPromise<Void>?) -> OnGracefulShutDown {
  500. let onGracefulShutdown: OnGracefulShutDown
  501. switch self.state {
  502. case .active(let state):
  503. self.state = ._modifying
  504. // Only close immediately if there are no open streams. The client doesn't need to
  505. // ratchet down the last stream ID as only the client creates streams in gRPC.
  506. let close = state.openStreams.isEmpty
  507. onGracefulShutdown = .sendGoAway(close)
  508. self.state = .closing(State.Closing(from: state, closePromise: promise))
  509. case .closing(var state):
  510. self.state = ._modifying
  511. state.closePromise.setOrCascade(to: promise)
  512. self.state = .closing(state)
  513. onGracefulShutdown = .none
  514. case .closed:
  515. onGracefulShutdown = .none
  516. case ._modifying:
  517. preconditionFailure()
  518. }
  519. return onGracefulShutdown
  520. }
  521. /// Returns whether the connection should be closed.
  522. mutating func beginClosing() -> Bool {
  523. switch self.state {
  524. case .active(let active):
  525. self.state = .closing(State.Closing(from: active, closePromise: nil))
  526. return true
  527. case .closing, .closed:
  528. return false
  529. case ._modifying:
  530. preconditionFailure()
  531. }
  532. }
  533. enum OnClosed {
  534. case succeed(EventLoopPromise<Void>)
  535. case unexpectedClose((any Error)?, isIdle: Bool)
  536. case none
  537. }
  538. /// Marks the state as closed.
  539. mutating func closed() -> OnClosed {
  540. switch self.state {
  541. case .active(let state):
  542. self.state = .closed
  543. return .unexpectedClose(state.error, isIdle: state.openStreams.isEmpty)
  544. case .closing(let closing):
  545. self.state = .closed
  546. return closing.closePromise.map { .succeed($0) } ?? .none
  547. case .closed:
  548. self.state = .closed
  549. return .none
  550. case ._modifying:
  551. preconditionFailure()
  552. }
  553. }
  554. }
  555. }