GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Chapter 21 - tcp_mojifinder.py crashes on empty search result · Issue #61 · fluentpython/example-code-2e

Chapter 21 - tcp_mojifinder.py crashes on empty search result #61

New issue
Copy link
New issue
Copy link
Open
#62
Open
Chapter 21 - tcp_mojifinder.py crashes on empty search result#61
#62
Copy link

Description

@timheiko
timheiko
opened on Aug 8, 2025
Issue body actions

Issue

If index.search(query) in tcp_mojifinder.py returns empty result, it crashes TCP because asyncio.StreamWriter.writelines(data) raises AssertionError: Data should not be empty error if data is an empty iterable.

How to reproduce

Start the TCP server

% ./tcp_mojifinder.py 
Building index.
Serving on ('127.0.0.1', 2323). Hit CTRL-C to stop.
...

Connect to the TCP server and send a search query which returns no results, e.g. missing

% nc localhost 2323
?> missing
% 

The TCP server terminal will spit out an error stack trace like

% ./tcp_mojifinder.py 
Building index.
Serving on ('127.0.0.1', 2323). Hit CTRL-C to stop.
 From ('127.0.0.1', 63253): 'missing'
Unhandled exception in client_connected_cb
transport: <_SelectorSocketTransport fd=7 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/Users/tim/projects/python/example-code-2e/21-async/mojifinder/./tcp_mojifinder.py", line 33, in finder
    results = await search(query, index, writer)  # <13>
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tim/projects/python/example-code-2e/21-async/mojifinder/./tcp_mojifinder.py", line 48, in search
    writer.writelines(lines)  # <4>
    ~~~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/streams.py", line 343, in writelines
    self._transport.writelines(data)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/selector_events.py", line 1174, in writelines
    self._write_ready()
    ~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/selector_events.py", line 1090, in _write_sendmsg
    assert self._buffer, 'Data should not be empty'
           ^^^^^^^^^^^^
AssertionError: Data should not be empty

Activity

  1. timheiko
    added a commit that references this issue on Aug 8, 2025

    Chapter 21 - fix tcp_mojifinder.py crashes on empty search result

    This issue will close once commit 28ededd is merged into the 'master' branch.
    28ededd
  2. marktech0813 commented on Nov 5, 2025

    @marktech0813
    marktech0813
    on Nov 5, 2025
    More actions

    hi, can I handle this issues now?

  3. marktech0813
    added a commit that references this issue on Nov 5, 2025

    Fix--tcp_mojifinder.py crashes on empty search result fluentpython#61

    fff4fbf
  4. marktech0813 commented on Nov 5, 2025

    @marktech0813
    marktech0813
    on Nov 5, 2025
    More actions

    Please check PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.