listings package introduces unnecessary linebreaks

I am using the listings package to include source code. This works pretty well, however, sometimes lines are broken, but the input does not continue on the following line, only the postbreak arrow is displayed.

It seems that the listings package calculates line breaks incorrectly or takes whatever is specified by postbreak into account. I already checked the listings manual but have not found a solution to this problem.

Minimal working example is:

\documentclass[12pt, a4paper]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{newcent}

\usepackage{color} % requirement
\usepackage{listings} % reference source code
% a version without custom colors taken from classicthesis
morekeywords={PassOptionsToPackage,selectlanguage},
keywordstyle=\color{blue},%\bfseries,
basicstyle=\small\ttfamily,
%identifierstyle=\color{NavyBlue},
stringstyle=\ttfamily,
numbers=left,%none
numberstyle=\scriptsize,%\tiny
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
breakatwhitespace=false,
%frameround=ftff,
frame=tb,
belowcaptionskip=.75\baselineskip,
captionpos=b,
literate={\>}{}{0\discretionary{>}{}{>}},
%frame=L
}

\begin{document}
\chapter{Hello World}
\section{Minimal Working Example}

aaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb \lstinline{all} do not use lambda functions.
\end{document}


Output is:

• Make a complete example that we can test. – Ulrike Fischer Sep 22 '17 at 9:04
• It's hard to help you without having some code to play with. Please provide us with a minimal, but working example (MWE). – TeXnician Sep 22 '17 at 9:05
• I did :). Hope this is minimal enough and you (@ulrike-fischer and @texnician) see the updated question. – inktrap Sep 22 '17 at 9:31
• It is not minimal enough as I had to comment out at least 15 options of \lstset to concentrate on problem. Anyway, the problem does not appear to show in this mwe if using breakatwhitespace=true, and the fact that it does with breakatwhitespace=false is probably a bug. You should report to package maintainer. – user4686 Sep 23 '17 at 9:38
• @jfbu okay, I will report this. Thanks for your answer and for the time you invested.Unfortunately, breakatwhitespace=true alone is not an option, because then I get overlong lines. – inktrap Sep 23 '17 at 11:01