Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storeFile raise SMBTimeout exception on files > 1k #218

Open
dmlos opened this issue Jan 18, 2024 · 2 comments
Open

storeFile raise SMBTimeout exception on files > 1k #218

dmlos opened this issue Jan 18, 2024 · 2 comments

Comments

@dmlos
Copy link

dmlos commented Jan 18, 2024

Our code started to fail with SMBTimeout:

  File "/upload_to_fileshare.py", line 62, in copy_file_from_s3_to_network_share
    self.connection.storeFile(fs_share_name, destination_folder, source_data_fp)
  File "/usr/local/airflow/.local/lib/python3.10/site-packages/smb/SMBConnection.py", line 376, in storeFile
    return self.storeFileFromOffset(service_name, path, file_obj, 0, True, timeout, show_progress = show_progress, tqdm_kwargs = tqdm_kwargs)
  File "/usr/local/airflow/.local/lib/python3.10/site-packages/smb/SMBConnection.py", line 408, in storeFileFromOffset
    self._pollForNetBIOSPacket(timeout)
  File "/usr/local/airflow/.local/lib/python3.10/site-packages/smb/SMBConnection.py", line 607, in _pollForNetBIOSPacket
    raise SMBTimeout
smb.base.SMBTimeout

After investigation appeared that it able to store 1k of byte data, hence the workaround was:

offset = 0
while offset < source_data_fp.getbuffer().nbytes:
    offset = self.connection.storeFileFromOffset(
        service_name=fs_share_name,
        path=destination_folder,
        file_obj=io.BytesIO(source_data_fp.read(1024)),
        offset=offset,
        truncate=True if offset == 0 else False,
    )
@miketeo
Copy link
Owner

miketeo commented Jan 18, 2024

@dmlos

  1. If it's convenient, can you share what does the original code look like?
  2. Have you tried uploading the file to the SMB server from a local filesystem instead of from a remote cloud storage?

@dmlos
Copy link
Author

dmlos commented Jan 18, 2024

@dmlos

  1. If it's convenient, can you share what does the original code look like?
  2. Have you tried uploading the file to the SMB server from a local filesystem instead of from a remote cloud storage?
  1. Original code:
with closing(io.BytesIO()) as source_data_fp:
    source_data_fp.write(
        s3_hook.get_key(bucket_name=s3_bucket_name, key=s3_key_source)
        .get()["Body"]
        .read()
    )

    source_data_fp.seek(0)

    self.connection.storeFile(fs_share_name, destination_folder, source_data_fp)
  1. I tested similar code on Windows Cloud PC and it works, issue appear on AWS MWAA environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants