fix crashes in connection when middleware raises and we expect it