Expect script hangs Linux

When I run script listed below it causes my Linux to hang. When it freezes I can do totally nothing, move cursor, switch to another terminal or whatever. Linux is just not responding and the only way out I know is a hard reset of PC.

#!/bin/bash
if [ $# -ne 1 ]; then
  echo "one parameter is needed: IP address of gateway"
  exit 1
fi

expect -d -c "
  spawn tftp $1
  expect \"tftp> \";
  send \"get /var/lib/tftpboot/fb0\\n\";
  expect {
    timeout {close; exit 1}
    \"tftp> \";    
  }
  send \"quit\\n\";
  #expect eof;
  close;
 "
echo RESULT_CODE $?

The problem occurs sometimes after first try of running this script, sometimes after second or third. Here is the output from my console in case of freeze:

$ ./dw_test.sh 192.168.1.122
expect version 5.43.0
spawn tftp 192.168.1.122
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {1394}

expect: does "" (spawn_id exp6) match glob pattern "tftp> "? no
tftp>
expect: does "tftp> " (spawn_id exp6) match glob pattern "tftp> "? yes
expect: set expect_out(0,string) "tftp> "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "tftp> "
send: sending "get /var/lib/tftpboot/fb0\n" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "tftp> "? no
get /var/lib/tftpboot/fb0

expect: does "get /var/lib/tftpboot/fb0\r\n" (spawn_id exp6) match glob pattern "tftp> "? no

If I uncomment "expect eof;" in script, this problem does not occur. It does not occur also, when "expect eof;" is commented together with send \"quit\\n\";. Just like the tftp "quit" command caused this problem.

What is the reason for this?

I generate this sort of thing with autoexpect or use ssh2 scp. You did not quote the pattern. Why not just expect the prompt and let the rest just flow by? Is this a single core cpu system, that one looping expect can lock it so well Are you on an xterm, or the console as only terminal?

I wouldn't expect even an infinite loop on a single core to hang linux! It's more robust than that. expect may have taken control of your terminal though.

You might be able to switch between different text terminals with ctrl-alt-f1 through ctrl-alt-f6, login and kill it from there. ctrl-alt-f7 is traditionally where the GUI resides.

Try setting a longer timeout. I believe the default is 10.

set timeout 60