Skip to content

Commit

Permalink
Fixup: clean comments and docstrings
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Dellweg <[email protected]>
  • Loading branch information
pedro-psb and mdellweg committed Nov 22, 2024
1 parent 9fe9421 commit 085a459
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
8 changes: 1 addition & 7 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,12 +1140,10 @@ async def finalize():
try:
download_result = await downloader.run()
except DigestValidationError:
# Cant recover from wrong data already sent.
# We should close the connection without sending an EOF in the response
await downloader.session.close()
close_tcp_connection(request.transport._sock)
raise RuntimeError(
f"We tried streaming {remote_artifact.url!r} to the client, but it"
f"We tried streaming {remote_artifact.url!r} to the client, but it "
"failed checkusm validation. "
"At this point, we cant recover from wrong data already sent, "
"so we are forcing the connection to close. "
Expand Down Expand Up @@ -1176,9 +1174,5 @@ def close_tcp_connection(sock):
l_onoff = 1
l_linger = 0 # 0 seconds timeout - immediate close
sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", l_onoff, l_linger))
# Another possibility is configure the socket to send a RST instead of FIN,
# but I'm not sure if that's required:
# https://serverfault.com/questions/242302/use-of-tcp-fin-and-tcp-rst
# sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
except (socket.error, OSError) as e:
log.warning(f"Error configuring socket for force close: {e}")
Original file line number Diff line number Diff line change
Expand Up @@ -114,39 +114,31 @@ def test_remote_content_changed_with_on_demand(
monitor_task,
file_distribution_factory,
):
"""When:
1. Sync a remote with fileA(digest=123)
2. On remote server, change fileA content: fileA(digest=456)
Then:
3. Get fileA from content app will cause a connection-close/incomplete-response.
"""
# Create a remote that points to a file repository with 3 iso files
GIVEN a remote synced on demand with fileA (e.g, digest=123),
WHEN on the remote server, fileA changed its content (e.g, digest=456),
THEN retrieving fileA from the content app will cause a connection-close/incomplete-response.
"""
# GIVEN
basic_manifest_path = write_3_iso_file_fixture_data_factory("basic")
remote = file_remote_ssl_factory(manifest_path=basic_manifest_path, policy="on_demand")

# Sync from the remote
body = RepositorySyncURL(remote=remote.pulp_href)
monitor_task(
file_bindings.RepositoriesFileApi.sync(file_repo_with_auto_publish.pulp_href, body).task
)
repo = file_bindings.RepositoriesFileApi.read(file_repo_with_auto_publish.pulp_href)

# Create a distribution from the publication
distribution = file_distribution_factory(repository=repo.pulp_href)

# Download the manifest from the remote
expected_file_list = list(get_files_in_manifest(remote.url))

# Overwrite the 3 iso files to have different content/digest
# WHEN
write_3_iso_file_fixture_data_factory("basic", overwrite=True)

# Assert response is incomplete
# THEN
get_url = urljoin(distribution.base_url, expected_file_list[0][0])
with pytest.raises(ClientPayloadError, match="Response payload is not completed"):
download_file(get_url)

# Assert with curl just to be sure
# Assert again with curl just to be sure.
result = subprocess.run(["curl", "-v", get_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert result.returncode == 18
assert b"* Closing connection 0" in result.stderr
Expand Down

0 comments on commit 085a459

Please sign in to comment.