[tor-bugs] #10532 [Tor]: [Tor relay] Random hangs

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri Jan 3 03:29:55 UTC 2014


#10532: [Tor relay] Random hangs
---------------------------+------------------------------
     Reporter:  mrc0mmand  |      Owner:
         Type:  defect     |     Status:  new
     Priority:  normal     |  Milestone:
    Component:  Tor        |    Version:  Tor: unspecified
   Resolution:             |   Keywords:
Actual Points:             |  Parent ID:
       Points:             |
---------------------------+------------------------------

Comment (by cypherpunks):

 Probably found where from loop can occur. Tor's writing functions designed
 to share with socket operations. And tor assume every bytes will be
 written.
 So it first:
 {{{
 static int
 write_chunks_to_file_impl(const char *fname, const smartlist_t *chunks,
                           int open_flags)
 {
   open_file_t *file = NULL;
   int fd;
   ssize_t result;
   fd = start_writing_to_file(fname, open_flags, 0600, &file);
   if (fd<0)
     return -1;
   SMARTLIST_FOREACH(chunks, sized_chunk_t *, chunk,
   {
     result = write_all(fd, chunk->bytes, chunk->len, 0);
     if (result < 0) {
       log_warn(LD_FS, "Error writing to \"%s\": %s", fname,
           strerror(errno));
       goto err;
     }
     tor_assert((size_t)result == chunk->len);
   });

   return finish_writing_to_file(file);
  err:
   abort_writing_to_file(file);
   return -1;
 }
 }}}
 controls it with assert.
 and
 {{{
 ssize_t
 write_all(tor_socket_t fd, const char *buf, size_t count, int isSocket)
 {
   size_t written = 0;
   ssize_t result;
   tor_assert(count < SSIZE_T_MAX);

   while (written != count) {
     if (isSocket)
       result = tor_socket_send(fd, buf+written, count-written, 0);
     else
       result = write((int)fd, buf+written, count-written);
     if (result<0)
       return -1;
     written += result;
   }
   return (ssize_t)count;
 }
 }}}
 by loop till success.

 Manual for write says:
 {{{
 write() writes up to count bytes from the buffer pointed buf to the file
 referred to by the file descriptor fd.

 The number of bytes written may be less than count if, for example, there
 is insufficient space on the underlying physical medium, or the
 RLIMIT_FSIZE resource limit is encountered
 }}}
 Does it means that it should to return error on second try of writing to
 overfilled file? Then why not to return error on first try? Or it actually
 means that for first try it will return fully written bytes and zero for
 every next try?
 Depends answer, need to fix this loop or no need to fix.

 It could happen if no space left. It's easy to test probably, or not
 triggerable for classic env without some special conditions like quotas
 etc?

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/10532#comment:22>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list